←back to thread

255 points rd07 | 4 comments | | HN request time: 0s | source
1. BigParm ◴[] No.41298338[source]
How does it occupy 30MB ram but 5MB disk space does it grow
replies(2): >>41298459 #>>41298681 #
2. a-french-anon ◴[] No.41298459[source]

  void *p = malloc(30 * 1024 * 1024);
replies(1): >>41420245 #
3. genezeta ◴[] No.41298681[source]
In case your question is sincere, this is normal.

Generally, a program on disk contains code. Part of that is the description of certain structures. Say you have an editor which can load a file, you have to have structures to hold that file, to keep track of the undo history, to represent the file with colours (syntax highlighting) and whatever. Your editor may have a Lua VM inside running plugins that you load. That VM will reserve additional memory to run those plugins. And so on.

All that only exists while the program is running, but not on disk.

4. BigParm ◴[] No.41420245[source]
Makes sense. It's intuitive when you specify a number of bytes. I have myself been allocating memory using "new" so idk how my broken brain asked such a dumbass question.