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

External array with variable size?

This topic is 5403 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Guest Anonymous Poster
Original post by Lode
[quote]Original post by Anonymous Poster

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