Free memory allocated from a function

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Free memory allocated from a function

Post by ne0h »

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
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Improve the code and free any pointers you have allocated. Don't forget to free images too.
Image
Upgrade your PSP
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

Yes, I know that this is the best solution but I'll see if ther's another possibility...
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

I've a newbie question, is better to do many if\else if or a switch\case loop? ( for execution speed performance )
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

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: Select all

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.
Image
Upgrade your PSP
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

Ok, thanks!
Super Sheep
Posts: 31
Joined: Sun Mar 23, 2008 2:16 am
Contact:

Post by Super Sheep »

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: Select all

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.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

I know but we were not talking about that, we were talking about the "slow down".
Image
Upgrade your PSP
Super Sheep
Posts: 31
Joined: Sun Mar 23, 2008 2:16 am
Contact:

Post by Super Sheep »

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.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Then why is my example terrible?
Image
Upgrade your PSP
Post Reply