GCMemAlloced behavior
BlitzMax Forums/BlitzMax Programming/GCMemAlloced behavior
| ||
In the code bellow, GCMemAlloced show no memory usage due to pixmap or bank objects. Why is that? SuperStrict Print "1:"+GCMemAlloced() Global Bank:TBank = CreateBank(4000*4000*4) ' 64Mb Print "2:"+GCMemAlloced() Global Pixmap:TPixmap = CreatePixmap(4000,4000,PF_RGBA8888) ' 64Mb Pixmap.ClearPixels($FF0000FF) Print "3:"+GCMemAlloced() Graphics 800,600 Global Image:TImage = LoadImage(Pixmap) While Not KeyHit(KEY_ESCAPE) Cls DrawImage(Image,0,0) DrawText("Allocated memory:"+String(GCMemAlloced()/1048576)+" Mb", 20, 20) Flip Wend Windows task manager gives about 160Mb used by the application. |
| ||
From the documentation: This function only returns 'managed memory'. The main body of a bank (and presumably a pixmap?) is actually just "simple" memory allocated with MemAlloc. The bank "object" is a simple managed wrapper around this memory block, which can free the block when the bank object is finalized. So, getting to the point, the main body of a bank isn't counted, because it wasn't allocated by the managed allocator in the first place. GCMemAlloced only reports on things it considers relevant to the GC (hint is in the name), not your whole application. Last edited 2012 |
| ||
Yes, but in the docs also writes "The amount of memory, in bytes, currently allocated by the application ". I know there are some commands in BMax which allocate "non managed memory" like MemAlloc, CreateStaticPixmap but I dont use these. Oh well, I guess I will need to have one global "size" counter for all data, to see how much memory my application use over time. Last edited 2012 |
| ||
I know there are some commands in BMax which allocate "non managed memory" like MemAlloc, CreateStaticPixmap but I dont use these. ...CreateBank is one of these. There might be a system call you can make to get this information? (If so, I don't know it off the top of my head.) The thing to bear in mind is that the OS deallocates memory much less aggressively than the application itself - it's not always easy or even possible to give back fragmented space - and even an accurate count of the allocated bytes in use by your application is likely to be lower at any given time than the Task Manager's report. So the "right" answer to your question also depends very much on which memory use statistic you actually want: one that helps you with resource management within the application; or one that tells you how it's interacting with the whole system? |
| ||
Or simply modify the relevant functions in brl.mod/blitz.mod/blitz_memory.c and get your info that way. Just dont forget to revert the changes for production builds ;) |