| View previous topic :: View next topic |
| Author |
Message |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Thu Sep 18, 2008 12:50 am Post subject: Free memory allocated from a function |
|
|
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 |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Thu Sep 18, 2008 1:40 am Post subject: |
|
|
Improve the code and free any pointers you have allocated. Don't forget to free images too. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Thu Sep 18, 2008 4:57 am Post subject: |
|
|
| Yes, I know that this is the best solution but I'll see if ther's another possibility... |
|
| Back to top |
|
 |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Thu Sep 18, 2008 5:29 am Post subject: |
|
|
| 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 |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Thu Sep 18, 2008 5:57 am Post subject: |
|
|
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 |
|
 |
ne0h
Joined: 21 Feb 2008 Posts: 386
|
Posted: Fri Sep 19, 2008 1:03 am Post subject: |
|
|
Ok, thanks! _________________ Get Xplora! |
|
| Back to top |
|
 |
Super Sheep
Joined: 23 Mar 2008 Posts: 31
|
Posted: Sat Sep 20, 2008 9:14 am Post subject: |
|
|
| 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 |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sat Sep 20, 2008 5:51 pm Post subject: |
|
|
I know but we were not talking about that, we were talking about the "slow down". _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Super Sheep
Joined: 23 Mar 2008 Posts: 31
|
Posted: Sun Sep 21, 2008 12:58 am Post subject: |
|
|
| 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 |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sun Sep 21, 2008 2:45 am Post subject: |
|
|
Then why is my example terrible? _________________
Upgrade your PSP |
|
| Back to top |
|
 |
|