Thread: Ideal memory space?

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    163

    Ideal memory space?

    My program calls alot of New to create dynamic memory array, so I'm doing some memory management by only calling New once and create a big page, and then allocate space from this page to new dynamic memory array. If the page runs out of space, I will create another page. So there's a linked list of pages.

    My question is what is the suitable size for this page? I read from some source code and the guy set it as 4096. Is this the ideal size? Is it related to our PC cache?

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    It depends on how much your program allocates. You can set your heap size limits in the linker.

    ex.
    /HEAP: 0x10000, 0x1000

    sets 64K(0x10000) of default heap and 4K(0x1000) of reserved heap. The defaults depend on what compiler and API you are using. Essentially, you could check this value by causing a heap overflow and counting the bytes you have allocated on it.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    durban,

    you mean i should allocate the page size to the size of the heap?

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    What is a reasonable page size directly depends on the application. Say on a average run your program uses 1024 kB of memory. On runs worst then that it uses say an extra couple kBs. So I'd probably set my inital pool to 1024kB and then allocate additional memory in 1kB blocks.

  5. #5
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    No, that would be using the whole heap which would be very bad, 99% chance you'll have an overflow. Use whatever portion you see fit for the size of heap you are using. If you're open for suggestions, I'd say using 5% of the heap per page, thus leaving plenty of room for other allocations and for other pages.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    i'm using g++ in linux, how do I check how much heap space I have? I'm sorry to ask questions that may sound stupid... =)
    Or is there any website that teaches us about managing the memory of our application in c++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sharing a Memory Space between two Processes
    By akm3 in forum C Programming
    Replies: 1
    Last Post: 04-02-2009, 02:06 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. Relate memory allocation in struct->variable
    By Niara in forum C Programming
    Replies: 4
    Last Post: 03-23-2007, 03:06 PM
  5. Memory handler
    By Dr. Bebop in forum C Programming
    Replies: 7
    Last Post: 09-15-2002, 04:14 PM