Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: My Image takes 16 byte per pixel  (Read 4166 times)

0 Members and 1 Guest are viewing this topic.

rmxhaha

  • Newbie
  • *
  • Posts: 8
    • View Profile
My Image takes 16 byte per pixel
« on: October 11, 2012, 11:03:42 am »
It's just a while ago I relized that SFML is taking much of my memory. If I calculate it roughly it will be about 16 byte per pixel. Is it normal or is it me being stupid ?

I know that graphic library with 32 bit in their option use 32 bit of data per pixel which means it uses 4 byte of data per pixel instead of 16 byte. So why is my program that uses SFML takes that much even though I set it in the sf::RenderWindow like this

sf::RenderWindow window(sf::VideoMode( 1024, 768, 32 ), "Title" );
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: My Image takes 16 byte per pixel
« Reply #1 on: October 11, 2012, 11:08:53 am »
And how do you check what memory is used?
Keep in mind the memory usage you see in the Task Manager or similar applications doesn't really say anything about the actual memory usage. It can well be that the OS reserves more space than needed and if another application needs that space it would give it free again.
So that leads to the question, how do you measure the memory usage? And what figures are we talking about?

Also what is your code base, I mean if you load 200 sf::Image into RAM obviously your application uses much memory, so you have to specify what your code base is. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rmxhaha

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: My Image takes 16 byte per pixel
« Reply #2 on: October 11, 2012, 11:17:08 am »
Well as you said I count the memory usage using task-manager...

counting on the pixel something like

The intial memory usage of SFML is about 7 MB in the task manager.

if the image is 800 x 600
The task manager will show you that it takes about 14 MB

that goes to the question why does 800x600 image takes so much memory

it does the same when it loads up 2 or more pictures

I tried 2 image 800x600 and the task manager shows it takes about 22 MB

so I jump to the conclusion 1 picture 800x600 takes 7MB
if you count it
7MB = 7000000 KB
7000000 : 800 : 600 = 14.5 byte

So I assume that 16 byte is the usage of memory per pixel.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: My Image takes 16 byte per pixel
« Reply #3 on: October 11, 2012, 11:23:57 am »
There's much more in play here, every variable in an application takes up it's own space as well. And as previously said the memory usage shown by the task manager shows the memory that Windows have allocated for the application and not the actual usage of the application. For instance if you are doing this in a debugging environment the memory usage would skyrocket as the debugger and the code associated with it would store away a lot of information.

Also remember that every variable, the actual application in it self and so on takes place in memory. If you want to monitor your memory usage you'll have to use a tool for that or implement some tracking functions yourself for that.

What IDE are you using and are you compiling in debug?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

rmxhaha

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: My Image takes 16 byte per pixel
« Reply #4 on: October 11, 2012, 11:31:32 am »
IDE ? I use code::blocks 10.24
and C++ Patch that is mentioned on the tutorial

I quite new in C++ application and making GUI and stuffs
so I don't know it's in debug mode or not

From what I always do I pressed F9 to compile

If the memory usage is not the actual memory usage of the application. Why would it be allocated in the first place. I mean if you do something like this

int * p = new int[1000];
 

I am sure that 4KB of data will be allocated no more no less.

so it's kinda confuse me, the way Windows allocate memory that isn't used by the application

MorleyDev

  • Full Member
  • ***
  • Posts: 219
  • "It is not enough for code to work."
    • View Profile
    • http://www.morleydev.co.uk/
Re: My Image takes 16 byte per pixel
« Reply #5 on: October 11, 2012, 11:41:17 am »
Assuming the image is stored in RAM and being enlarged stretched in RAM, an 800*600 image will actually be 1024*1024 pixels due to how textures work. RAM for speed there.


Also the OS may overallocate memory and can hesitant about releasing it
again unless it really needs to. The programs ram usage survived growing after all, why risk shrinking it when it may grow again?

Then you probably have other behind the scenes stuff the OS will do...
« Last Edit: October 11, 2012, 12:00:05 pm by MorleyDev »
UnitTest11 - A unit testing library in C++ written to take advantage of C++11.

All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: My Image takes 16 byte per pixel
« Reply #6 on: October 11, 2012, 11:51:57 am »
If the memory usage is not the actual memory usage of the application. Why would it be allocated in the first place.
so it's kinda confuse me, the way Windows allocate memory that isn't used by the application
I theory (and that's what you mostly need to know) you only allocate that space and practically you'll also only be able to work with that space.
But imagine an application like this:
for(unsigned int i = 0; i<10000; ++i)
{
    int* k = new int;
    delete k;
}
This now allocates and deletes 10000 times some integer. Now imagine your application would need to query the OS for each and every allocation to get some space (that is how memory management works, the OS is the 'master') your application would be horrible slow, because querying the OS doesn't take zero nanoseconds. Thus when you once request some space from the OS it allocates more than you actually need and if you delete it, the OS doesn't immediately take that back, so whenever you'd need more space the application already has some space left over and if that's not enough (anymore) it can request more.

This is just one aspect of the whole memory management thing and every OS handles it a bit different and I guess nobody can exactly say how every little detail in every situation works. ;)
That doesn't mean it's not worth learn more on that topic, but it means that there's no reason to worry when you see a higher memory usage in the Task Manager than you'd have expected.

Also in my opinion it's not really a topic that should concern you that much when starting of with programming. It's sure intelligent to not use too much resources for no reason, but trying to reduce/optimize code that doesn't really exist yet is not the best approach to programming, mainly because one could essential always optimize further and thus one would never reach the wanted aim. So it's good to understand what is going on underneath and try to write code accordingly, but getting to a new programming language and library it's probably better to understand how to use the API first and then later maybe try to understand how it works underneath. ;)

Summary: Programming is all about abstraction (e.g. if you know the interface of A you don't necessarily need to know how A connects with B). ;)
« Last Edit: October 11, 2012, 11:55:48 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rmxhaha

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: My Image takes 16 byte per pixel
« Reply #7 on: October 11, 2012, 12:03:10 pm »
Ok I get it now...
It's just that the memory managements....

I know that C++ program tend to allocate more than they need because of the OS Query things.
I just don't really care about it until I see big numbers.

Thanx for the answers
So sorry to bother you all for me being newbie

 

anything