Somehow I can allocate up to 95ish GB of ram but where is that memory coming from? My computer isn't even using all its ram as expected and my storage doesn't seem to decrease at all either. What's going on?
#Allocating more RAM than available
67 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
my code: c int count = 0; while(1) { int *p = malloc(ONEGB); if (p == NULL) { printf("malloc refused after %d Gb\n", count); return 0; } memset(p,1,ONEGB); printf("got %d GB\n", ++count); if (count == 95) while(1); }
i have the while loop set at count == 95 because it just crashes afterwards and the (p == NULL) isn't even run (or at least it doesn't print and return 0)
Often times windows will let you store temp ram on a drive. Its not fast and it causes stuttering, but for chrome or something its better than not storing data. P.s. This is my guess based on my overclocking experiences.
ic. The only thing is that it doesn't look like my drive memory is increasing but idk
You do notice that ain't Windows right?
Yea, but was just giving a reference @heady imp
Again, only from my experience with a windows operating system
Could be doign the same thing though
Try looking at the compressed amount.
what is this even a screenshot of
a.out - 95 GB
what are you taking a picture of
did you do like an ls or something
activity monitor
showing how much ram the process is using
i think maybe what happened is a memory leak
i don't know the implementation of the c standard library or what software chain is involved in the activity monitor or what it is pulling from the OS or what the OS is keeping track of
but your program clearly is written to leak one gigabyte of memory every iteration of that looo
i mean the point is to fill up as much mem as i can
i understand
but I'm wondering if somehwere in this software chain something is not being updated due to the memory leak and something else is tricking something else
IDK
idk
it could be that something is optimizing and recognizing that memory is no longer used and something else doesn't know which is why there's a disconnect
that's what I meant before
i explained it badly
you could try to use a debugger to see also
are you familiar with gdb
the picture disappeared
anyways this might be a bug in something in the OS or library for something tbh
well maybe you don't need to use gdb if you don't know it but instead you can edit the program to store these pointers to a global array of pointers and then after the 95 loops run you can do another 95 loops checking the contents and printing the pointer to see if there's any funny business
and in case something is optimizing it out because you don't use it ever, then it would crash because now you use it
Well did you do this?
ok well tbh what I just said it's what I would do before gdb now
not yet b/c i have to run the program again but the compressed amount for the ram is in the screen shot
I want you to watch it as the program runs.
ok
yea it grew by .3 GB if any
So that might be where your memory is.
yea but how is it supposed to hold multiple gigs
Your data is all uniform.
I have a theory: Generally speaking, at least in my case, allocating more memory than physically available is impossible. However, OS have the ability to extend the memory by virtually increasing the RAM which involves using the drive memory. So, although malloc can only use the heap to dynamically store memory, the OS kernel can do whatever it wants to. So, your app is using that ammount of space because you did not use the free() function to deallocate the memory. This is called memory leak. And it is not showing the printf message because the OS is populating the drive memory once the heap is full. So it allwyas returns a non-nullptr.
yea but i don't see drive mem increase? unless it doesn't show that
well the swap file will normall already exist and have a fixed size
that's assuming you have a swap file and not a swap partition
is it swap file or swapfile? idk
@signal folio Has your question been resolved? If so, run !solved :)
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
:)_ _
Anyways @signal folio, please remember to allways free the allocated memory once it is not necessary anymore. Otherwise, the system will keep certain chunks of data reserved that are not being used! It has been a pleasure helping you out!