Jump to content
  • Advertisement
Sign in to follow this  
BaneTrapper

How to find a size of variable

This topic is 2221 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

Hello.
Language barrier hitting me hard.
How do i check how much bits does a SDL_Surface take?
its size is 1000x1000.

Whats libraries allow that king of stuff... or what are ways to check/know size of variables

Share this post


Link to post
Share on other sites
Advertisement
There are two different sizes for an object like that.

Think of the SDL_Surface as a container.

You can look at the size of the container. You can also look at the size of the thing it holds.


Think of it like the size of a trash bag, which itself is a tiny sheet of plastic, vs the volume of trash it can contain.



sizeof(SDL_Surface) will give the size of the container, probably 48 bytes.

It contains an array of pixels, which is (surface.y * surface.pitch) bytes. For a 1000x1000 pixel array it is probably close to 4MB in size. Edited by frob

Share this post


Link to post
Share on other sites

There are two different sizes for an object like that.

Think of the SDL_Surface as a container.

You can look at the size of the container. You can also look at the size of the thing it holds.


Think of it like the size of a trash bag, which itself is a tiny sheet of plastic, vs the volume of trash it can contain.



sizeof(SDL_Surface) will give the size of the container, probably 48 bytes.

It contains an array of pixels, which is (surface.y * surface.pitch) bytes. For a 1000x1000 pixel array it is probably close to 4MB in size.


Well i did some logical thinking if you can call it that
1000x1000(size of image) 1,000,000 pixels.
Each pixel holds RGB , and Alpha i think.
Therefore 4,000,000 bit's. 4mb...
Seams pretty low for a 1000x1000 image that's why i make this post.
Am no expert.

And i am asking how many cans, food leftover, cereal boxes are in plastic trash bag(SDL_Surface). Edited by BaneTrapper

Share this post


Link to post
Share on other sites

Well i did some logical thinking if you can call it that
1000x1000(size of image) 1,000,000 pixels.
Each pixel holds RGB , and Alpha i think.
Therefore 4,000,000 bit's. 4mb...
Seams pretty low for a 1000x1000 image that's why i make this post.

You probably want allow for more than 1 bit per colour. Otherwise, 4 megabytes for a 1000x1000 pixel image sounds reasonable to me. Edited by Bregma

Share this post


Link to post
Share on other sites
SDL_Surface has a member format which is of type SDL_PixelFormat http://sdl.beuc.net/sdl.wiki/SDL_PixelFormat, it tells you all you need to know about how pixels are represented in a surface. It has a member BytesPerPixel, which is what you need to figure out the size of your Surface, given the number of pixels.

Share this post


Link to post
Share on other sites

SDL_Surface has a member format which is of type SDL_PixelFormat http://sdl.beuc.net/...SDL_PixelFormat, it tells you all you need to know about how pixels are represented in a surface. It has a member BytesPerPixel, which is what you need to figure out the size of your Surface, given the number of pixels.

Not quite.

There is potentially additional information per scan line. Often a scan line will continue to a 64-byte or 128-byte boundary, with dead information at the end. That's why the surface's pitch value exists. According to the docs, the pitch stores the bytes per scanline, not pixels per scanline.

As mentioned in my earlier reply, (surface.y * surface.pitch) should give the size of the pixel array.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!