Archived

This topic is now archived and is closed to further replies.

Spudder

Preventing SDL from using 100% CPU

Recommended Posts

Spudder    385
I''m making a game using SDL and noticed that when the game is running the CPU usage is around 95%, i''ve read through the SDL docs but havent found anything for this so i''m hoping someone heres knows of a solution or can point me in the direction of one. And before anyone says it i have Googled for an answer but nothin came up.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
it''s not SDL most likely, if you''re running the game loop, that''s the reason why it''s using so much CPU power. I don''t know what stage you''re in in development but if it''s early on, your message pump and loop will eat all the processer. It goes down later when you start moving memory and pushing stuff to the vid card.

Share this post


Link to post
Share on other sites
255    368
You could look into process/thread priorities. Perhaps changing the CPU priority of the game could be an option for the user. Be careful with ''realtime'' and ''idle'' though.

Share this post


Link to post
Share on other sites
RamboBones    102
Write program as follows

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
while(1){}
return 0;
}

Program will take up 100%, or close enough to, CPU time. Replace the function body with

{
unsigned long SomeData[5000];
while(1){memset(SomeData,0,sizeof(SomeData);}
return 0;
}

Program will take up less processor time.

Share this post


Link to post
Share on other sites
yspotua    122
You could also look into use the multithreaded functionality of SDL. You could then put your input loop into thread that is only called when an event is generated instead of running constantly.

Share this post


Link to post
Share on other sites