Archived

This topic is now archived and is closed to further replies.

Lode

External array with variable size?

Recommended Posts

How can I make an array that's external, and can change size while the program runs (in C)? It's for a video buffer for a program with changing screen resolutions. It doesn't have to be completely external, just in one c file. Thanks. PS I guess this question is pretty beginner so I ask it here. [edited by - Lode on March 1, 2003 2:39:29 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
"External"?


That was the most useless reply I could imagine.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Lode
[quote]Original post by Anonymous Poster
"External"?


That was the most useless reply I could imagine.

If it didn''t accur to you,
"External"? == Elaborate on that, because that doesn''t seem to be the correct term.

Share this post


Link to post
Share on other sites
no, it wasnt, he was asking because your post contained something that doesn''t fit in. I still dont know what you mean for sure, but I think I have a slight idea.


What you want is a global, and a function to resize it. Because of this, it needs to be a pointer. here is an example:

  
char *vbuf;
int x, y; // old size of the vbuf.


bool Resize( int NewX, int NewY )
{
if( NewX < x || NewY < y )
return false;
char NewVbuf;
NewVbuf = new char[NewX * NewY];
for( int i = 0; i < x; i++ )
{
for( int n = 0; n < y; n++ )
NewVbuf = vbuf[n*y+i];
}
delete vbuf;
vbuf = NewVbuf;
x = NewX;
y = NewY;
return true;
}


pretty much. could use some extra things, like making the new buf smaller than the old one, but...

// Eric

Share this post


Link to post
Share on other sites