开发者

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

开发者 https://www.devze.com 2023-03-17 13:45 出处:网络
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 a

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 'was开发者_如何学Cting' 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消