|
|
(From Allegro documentation) typedef struct BITMAP int w, h; - size of the bitmap in pixels int clip; - non-zero if clipping is turned on int cl, cr, ct, cb; - clip rectangle left, right, top, and bottom unsigned char *line[]; - pointers to the start of each line There is some other stuff in the structure as well, but it is liable to change and you shouldn't use anything except the above. The `w' and `h' fields can be used to obtain the size of an existing bitmap: bmp = load_bitmap("file.bmp", pal); allegro_message("Bitmap size: (%dx%d)\n", bmp->w, bmp->h); |
BITMAP *create_bitmap(int width, int height); Creates a memory bitmap sized width by height. The bitmap will have clipping turned on, and the clipping rectangle set to the full size of the bitmap. The image memory will not be cleared, so it will probably contain garbage: you should clear the bitmap before using it. This routine always uses the global pixel format, as specified by calling set_color_depth(). The minimum height of the BITMAP must be 1 and width can't be negative. Example: /* Create a 10 pixel tall bitmap, as wide as the screen. */ BITMAP *bmp = create_bitmap(SCREEN_W, 10); if (!bmp) abort_on_error("Couldn't create bitmap!"); /* Use the bitmap. */ ... /* Destroy it when we don't need it any more. */ destroy_bitmap(bmp); Returns a pointer to the created bitmap, or NULL if the bitmap could not be created. Remember to free this bitmap later to avoid memory leaks. |
Also, use new instead of malloc(). It looks cleaner |
|
|
I find malloc() more customizable than the "new" operator. In my opinion the fact you can decide the size in bytes of memory allocation makes it better than new (also it needs more attention). |
You do realize that a char is (as far as I can remember) ALWAYS 1 byte long |
So, what's the problem? You need to load many (no idea how much "many" is to you. To me it would be over 10000) images and want to reduce HDD usage? Well, unless the same image is going to be loaded more that once, you don't have much of a choice. If you are going to load the same image more than once, you could use a memory cache. Keep in mind that you'll be moving the strain from HDD access to RAM usage. |
won't be able to use more than... 5 MB/s. You only need to worry if you're using a considerable amount of bandwidth (usually more than 50 or 100 MB/s) for a prolonged period of time (I suppose it should be somewhere between a few hours and a few days). But those numbers only come up during tasks such as copying entire disks, and they don't run for more than a few hours |
Yes, I know it. But I can't understand what you are trying to say, I'm sorry. If you are talking about my example of usage of new and delete you can see that I use a pointer that points to an array of chars (or, better, an array of bytes, seeing the fact I use it as a binary data storer). If you are talking about the (void *) malloc function I don't also understand what you are meaning. Probably I lost a step of your reply, sorry again. |
S *a=(S *)new char[sizeof(S)]
. This is, of course, as retarded as doing long *b=(long *)new char[sizeof(long)]
. So honestly, I don't know what advange other than a small speed increase you're getting from using malloc() over new.