CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2005
    Posts
    15

    larger array size like (100000000)

    i need to write a template dat can handle a larger array size like

    i need it urgently
    plz help me

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128

    Re: larger array size like (100000000)

    When large memory block is needed, it is usually not sufficient for the stack to provide. Instead, you can allocate the memory from heap using operator "new" but don't forget to free the memory using operator "delete []". On the other hand, you may want to relook at your design since needing large memory block is often a sign of bad design.

  3. #3
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: larger array size like (100000000)

    1e8 is close to a gigabyte. (A gigabyte is a bit more than 1e9 bytes but see below).

    Depending on the size of your object (array of what?), it may not be possible in a 32-bit environment, even if you have that amount of RAM (and virtual memory) available.

    The actual amount of memory that needs to be allocated is the size of the array multiplied by sizeof( object ).

    Perhaps you are creating a big hash-table or a big cache, but I don't know.
    Last edited by NMTop40; July 27th, 2005 at 04:26 AM.

  4. #4
    Join Date
    May 2005
    Posts
    15

    Re: larger array size like (100000000)

    tnx 4 ur quick response
    actually i need define it in a template class. ineed define it 4 unlimited size.
    it may b larger then physical memory size.

    the data will b cached into a file n retrive 4m dat file.i need it urgently.
    as a example
    class ar<int>ss=new
    ar<int>(100000000);
    plz hlp me.

  5. #5
    Join Date
    Sep 2004
    Posts
    7

    Post Re: larger array size like (100000000)

    hi,
    the maximum block of memory you can allocate in the heap is 0xFFFFFFE0 (_HEAP_MAXREQ). if you're trying to use something like char buffer[_your_size], which will be created in the stack, _your_size depends on the stack size - it can be set with the /STACK compile option (i have no idea what the maximum value is here)

    the thing is 100mil is kinda small compared with _HEAP_MAXREQ (~4,294mil)... so if you allocate memory you shouldn't have any trouble.

    if you need more than 4.2billion bytes... well... there are some things you can do, like using more than one process and some rpc or ipc method to allocate and access elements between them (but the os will probably swap you to madness) or using multiple files to hold elements - for example, to allocate 6 billion bytes you can use 6 files of 1GB and you find byte x by accessing file x/1G and reading the x%1G byte.

    cristian traum.
    Last edited by cristraum; July 27th, 2005 at 04:53 AM.

  6. #6
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: larger array size like (100000000)

    Quote Originally Posted by cristraum
    hi,
    the maximum block of memory you can allocate in the heap is 0xFFFFFFE0 (_HEAP_MAXREQ). if you're trying to use something like char buffer[_your_size], which will be created in the stack, _your_size depends on the stack size - it can be set with the /STACK compile option (i have no idea what the maximum value is here)
    In fact with Windows, the limitation of allocated memory is 2GB (except if a switch is activated on some version of windows, so the limitation is 3GB).
    Of course you cannot allocate 2GB, because there is the code size, the stack size, and some memory using a few megabytes of virtual memory, so in fact you can just allocate (2GB-a few megabytes).
    With the /STACK switch you can reserve a huge amount of memory.
    In fact you are just limited by the virtual memory space.

    But (especially for multithread program), you should not reserved much memory for the stack (if you have much recursions, you can reserve 32 MB or 64 MB), the usage of this memory is less flexible than the heap.
    For single threaded applications, you just need to know that the virtual memory reserved for the stack cannot be used for the heap.
    So, if your program use huge recursions, and allocate few memory on the heap, it is correct to reservea huge stack (256MB or more).

    You can use std::vector, which allocates on the heap.

  7. #7
    Join Date
    Sep 2004
    Posts
    7

    Re: larger array size like (100000000)

    Quote Originally Posted by SuperKoko
    In fact with Windows, the limitation of allocated memory is 2GB (except if a switch is activated on some version of windows, so the limitation is 3GB).
    right, i forgot about the kernel space <img>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured