#Allocating more RAM than available

67 messages · Page 1 of 1 (latest)

signal folio
#

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?

sturdy hamletBOT
#

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.

signal folio
#

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)

gloomy fable
#

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.

signal folio
#

ic. The only thing is that it doesn't look like my drive memory is increasing but idk

heady imp
gloomy fable
#

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

heady imp
feral hinge
#

a.out - 95 GB

#

what are you taking a picture of

#

did you do like an ls or something

signal folio
#

showing how much ram the process is using

feral hinge
#

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

signal folio
#

i mean the point is to fill up as much mem as i can

feral hinge
#

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

signal folio
#

idk

feral hinge
#

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

signal folio
#

either way, memory is being soaked up and idk where and how

#

oh maybe

feral hinge
#

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

signal folio
#

maybe

#

how would i go about debugging this anyway

feral hinge
#

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

signal folio
#

ik gdb

#

pretty sure i did that too

feral hinge
#

and in case something is optimizing it out because you don't use it ever, then it would crash because now you use it

heady imp
feral hinge
signal folio
heady imp
#

I want you to watch it as the program runs.

signal folio
#

ok

signal folio
heady imp
#

So that might be where your memory is.

signal folio
#

yea but how is it supposed to hold multiple gigs

heady imp
#

Your data is all uniform.

signal folio
#

ah

#

huh

cunning dragon
#

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.

signal folio
#

yea but i don't see drive mem increase? unless it doesn't show that

prime wing
#

that's assuming you have a swap file and not a swap partition

#

is it swap file or swapfile? idk

signal folio
#

idk

#

well ty!!

sturdy hamletBOT
#

@signal folio Has your question been resolved? If so, run !solved :)

signal folio
#

!solved

sturdy hamletBOT
#

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

signal folio
#

:)_ _

cunning dragon
#

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!

signal folio
#

I

#

That’s the point!!