简体   繁体   中英

C++ (Allegro Library) Bitmap Two-Dimensional Array Question

I have a quick question. I am using C++ with the Allegro library.

If I make the following declaration BITMAP* blocks[600][14]; , is it going to be wasted space if I only occasionally am using all 14 all of the second dimension or is that space only used when I specifically declare that part of the array?

For example:

BITMAP* blocks[600][14];
blocks[0][0] = load_bitmap("brick.bmp", NULL);
blocks[1][0] = load_bitmap("brick2.bmp", NULL);

Am I 'wasting' space by not using blocks[0][1] , blocks[0][2] etc.?

Thanks,

Will.

In C++, arrays are contiguous so yes, you are 'wasting' the additional elements if you don't use them.

However, what you are wasting is only a single pointer (8 bytes on a 64-bit machine); not the actual bitmap data. So even if you use only one BITMAP* element in your 600x14 array you're wasting ~67kB; which isn't a massive amount in a modern desktop machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM