Created
October 27, 2015 14:14
-
-
Save smalik/48b528e9445d7363bfd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Get memory allocation on an object by object basis. Loop over your namespace and print out memory used by all objects. | |
| for (itm in ls()) { | |
| print(formatC(c(itm, object.size(get(itm))), format="d", big.mark=",", width=30), quote=F) | |
| } | |
| # Print memory used collectively in namespace | |
| print(memory.profile()) | |
| # To estimate if vector (of numbers) will fit into memory so we can predict the memory usage based on vector size. | |
| # To find the size of a matrix or a dataframe just multiply out the number of vectors used or just loop over the vectors in the data frame or matrix. | |
| estimate_dataSize = function(nsize, ntype = "numeric") { | |
| if(ntype == "integer") { | |
| byte_per_number = 4 | |
| } else if(ntype == "numeric") { | |
| byte_per_number = 8 | |
| } else { | |
| stop(sprintf("Unknown number_type: %s", number_type)) | |
| } | |
| byte_size = (nsize * byte_per_number) | |
| class(byte_size) = "object_size" | |
| print(byte_size, units = "auto") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment