Click to See Complete Forum and Search --> : larger array size like (100000000)


sirajcuet
July 27th, 2005, 04:02 AM
i need to write a template dat can handle a larger array size like

i need it urgently
plz help me

Kheun
July 27th, 2005, 04:20 AM
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.

NMTop40
July 27th, 2005, 04:24 AM
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.

sirajcuet
July 27th, 2005, 04:45 AM
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.

cristraum
July 27th, 2005, 04:50 AM
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.

SuperKoko
July 27th, 2005, 05:32 AM
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.

cristraum
July 27th, 2005, 06:04 AM
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>