[英]C++ (Allegro Library) Bitmap Two-Dimensional Array Question
I have a quick question.我有一个快速的问题。 I am using C++ with the Allegro library.
我将 C++ 与 Allegro 库一起使用。
If I make the following declaration BITMAP* blocks[600][14];
如果我做出以下声明
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? ,如果我只是偶尔使用所有 14 个第二维,或者仅在我明确声明数组的那部分时才使用该空间,是否会浪费空间?
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.?我是否通过不使用
blocks[0][1]
、 blocks[0][2]
等来“浪费”空间?
Thanks,谢谢,
Will.将要。
In C++, arrays are contiguous so yes, you are 'wasting' the additional elements if you don't use them.在 C++ 中,arrays 是连续的,所以是的,如果你不使用它们,你就是在“浪费”额外的元素。
However, what you are wasting is only a single pointer (8 bytes on a 64-bit machine);但是,您浪费的只是一个指针(在 64 位机器上为 8 个字节); not the actual bitmap data.
不是实际的 bitmap 数据。 So even if you use only one BITMAP* element in your 600x14 array you're wasting ~67kB;
因此,即使您在 600x14 数组中仅使用一个 BITMAP* 元素,您也浪费了大约 67kB; which isn't a massive amount in a modern desktop machine.
在现代台式机中,这并不是一个庞大的数量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.