forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Free memory allocated from a function

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Thu Sep 18, 2008 12:50 am    Post subject: Free memory allocated from a function Reply with quote

Hi,
I'm still working on Xplora, but I've see that the memory is not completely free when returning from the Text editor, so there's a solution to free all the memory allocated by this function or I can only try to improve the code to free the allocated memory?

Thanks in advance
Back to top
View user's profile Send private message
Pirata Nervo



Joined: 09 Oct 2007
Posts: 409

PostPosted: Thu Sep 18, 2008 1:40 am    Post subject: Reply with quote

Improve the code and free any pointers you have allocated. Don't forget to free images too.
_________________

Upgrade your PSP
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Thu Sep 18, 2008 4:57 am    Post subject: Reply with quote

Yes, I know that this is the best solution but I'll see if ther's another possibility...
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Thu Sep 18, 2008 5:29 am    Post subject: Reply with quote

I've a newbie question, is better to do many if\else if or a switch\case loop? ( for execution speed performance )
Back to top
View user's profile Send private message
Pirata Nervo



Joined: 09 Oct 2007
Posts: 409

PostPosted: Thu Sep 18, 2008 5:57 am    Post subject: Reply with quote

it is better to use switch (when you can) instead of many if's. It makes your code neat and clear. I don't know about speed but it might be the same.
Remember that if's can make things VERY slow. Example:
Code:

char charv[200];
sprintf(charv, "my name is blablabla");
if (strlen(charv) >= 100 && strcmp(charv, "my name is blablabla") == 0)
{
  // etc
}


It executes 2 functions:
strlen
strcmp

the actual if does not slow down but its conditions can slow down your program.
_________________

Upgrade your PSP
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Sep 19, 2008 1:03 am    Post subject: Reply with quote

Ok, thanks!
_________________
Get Xplora!
Back to top
View user's profile Send private message
Super Sheep



Joined: 23 Mar 2008
Posts: 31

PostPosted: Sat Sep 20, 2008 9:14 am    Post subject: Reply with quote

Pirata Nervo wrote:
it is better to use switch (when you can) instead of many if's. It makes your code neat and clear. I don't know about speed but it might be the same.
Remember that if's can make things VERY slow. Example:
Code:

char charv[200];
sprintf(charv, "my name is blablabla");
if (strlen(charv) >= 100 && strcmp(charv, "my name is blablabla") == 0)
{
  // etc
}


It executes 2 functions:
strlen
strcmp

the actual if does not slow down but its conditions can slow down your program.


Thats pretty much the same as running two if statements in the assembly.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Pirata Nervo



Joined: 09 Oct 2007
Posts: 409

PostPosted: Sat Sep 20, 2008 5:51 pm    Post subject: Reply with quote

I know but we were not talking about that, we were talking about the "slow down".
_________________

Upgrade your PSP
Back to top
View user's profile Send private message
Super Sheep



Joined: 23 Mar 2008
Posts: 31

PostPosted: Sun Sep 21, 2008 12:58 am    Post subject: Reply with quote

Pirata Nervo wrote:
I know but we were not talking about that, we were talking about the "slow down".


Exactly...
The number of conditions (n) in a single if can also be represented as n if statements.

The actual if CAN cause slowdowns, as it is an instruction, but its so small.

Your example is terrible btw.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Pirata Nervo



Joined: 09 Oct 2007
Posts: 409

PostPosted: Sun Sep 21, 2008 2:45 am    Post subject: Reply with quote

Then why is my example terrible?
_________________

Upgrade your PSP
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group