SDL Initialization ! About Memory Consuming.

main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
int main(int argc,char *argv[])
{
	if( initialization() == false )
	{
		return 1;
	}

	event_handler();

	clean_up();

	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
bool initialization()
{

	if( SDL_Init(SDL_INIT_EVERYTHING) == -1 )
	{
		return false;
	}

	if( TTF_Init() == -1 )
	{
		return false;
	}

	//Initialize SDL_mixer
	if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
	{
		return false;    
	}

	screen = SDL_SetVideoMode(screen_width,screen_height,screen_bpp,screen_flags);

	if(screen == NULL)
	{
		return false;
	}

	//Update the screen
	if(SDL_Flip(screen) == -1)
	{
		return false;
	}

	//Success
	return true;
}


1
2
3
4
5
6
7
void clean_up()
{
	SDL_FreeSurface(screen);
	SDL_Quit();
	TTF_Quit();
	Mix_CloseAudio();
}


TL;DR :
As you can see,I initialized SDL,TTF,Mixer (also SDL_image.h), created new surface named screen,and cleaned up every end of the main loop,did not forget to free the screen surface.But it still consumes 4MB RAM when still.Is this normal ? Or do I need some more optimization.

Maybe after all those initializations,4 MB is normal,and I didn't have any memory leak.
...and?

What's the problem? You make it sound like 4 MB is a lot.

Windows calculator uses almost 7 MB.

EDIT:

fwiw, I don't see a leak in your code, although I'm not sure if you're supposed to free the surface given to you by SDL_SetVideoMode
Last edited on
Topic archived. No new replies allowed.