PDA

Click to See Complete Forum and Search --> : Big ol' varible


Cbomb
Jun 1st, 2001, 05:54 PM
How can I create a varible that takes up 160Mb in memory and then unload it? (memory flush) Thanks in advance.

parksie
Jun 1st, 2001, 06:17 PM
Couldn't you just keep allocating large blocks of memory until you get to 160MB?
#define BUFFER 65536
#define NUMBUFS 2560
// 160MB = BUFFER * NUMBUFS
char **pData;
int i;
pData = new char*[NUMBUFS];
for( = 0; i < NUMBUFS; i++) {
pData[i] = new char[BUFFER];
}

for( = 0; i < NUMBUFS; i++) {
delete[] pData[i];
}

delete[] pData;

Not totally sure about that, but it should do the trick...I expect the program will die before it allocates 160MB though.

Vlatko
Jun 1st, 2001, 08:18 PM
Change the two

for( = 0; i < NUMBUFS; i++)


to


for(i = 0; i < NUMBUFS; i++)


An i is missing?;) ;)

parksie
Jun 2nd, 2001, 06:13 AM
Yep, they're missing...I moved the int i away from both and forgot to put it back again :rolleyes: