Determining Allocated Memory in Delphi

One of the new features of BDS 2006 is a new memory manager. As a result, all of the old ways to get the amount of allocated memory have been deprecated. It is surprising to me that they did not give you an alternative way to get this information, but thanks to some searching of the FastMM code, here is a method to get the amount of allocated memory for your process.

function AllocatedMemory: Cardinal;
var
  MemoryManagerState: TMemoryManagerState;
  SmallBlockState: TSmallBlockTypeState;
begin
  GetMemoryManagerState(MemoryManagerState);
  Result := 0;
  for SmallBlockState in MemoryManagerState.SmallBlockTypeStates do
    Inc(Result, SmallBlockState.AllocatedBlockCount * SmallBlockState.UseableBlockSize);
  Inc(Result, MemoryManagerState.TotalAllocatedMediumBlockSize);
  Inc(Result, MemoryManagerState.TotalAllocatedLargeBlockSize);
end;

8 Responses to “Determining Allocated Memory in Delphi”

  1. Psychic Advice Says:

    Great blog, but i couldnt understand where can i subscribe to your rss feed?

  2. Hypnotize Anyone Says:

    Cool. Come by and hypnotize yourself if you please ;)

  3. make money blogging Says:

    I wish you would post more often…this is my “coffee drinking” blog:) Edgar Allen

  4. Brian Owens Says:

    Interesting point of view. I’ll consider changing my mind about this but for now I still don’t see things the same way you do.

  5. Pete Jones Says:

    You’re right on. Couldn’t have said it better myself. -Pete

  6. matt richkid Says:

    Love your site it is very informative am going to research the other posts to see what else I can learn, cheers! and keep up the great work!

  7. James Says:

    Hi, I found your blog on this new directory of WordPress Blogs at blackhatbootcamp.com/listofwordpressblogs. I dont know how your blog came up, must have been a typo, i duno. Anyways, I just clicked it and here I am. Your blog looks good. Have a nice day. James.

  8. Pak Tam Says:

    Nice. Thanks. :) Pak Tam

Leave a Reply