π
<-

ndless memory map

C, C++, ASM...

Re: ndless memory map

Unread postby nspiredev500 » 06 Jul 2020, 16:39

If you aren't willing to pay the size cost, maybe consider the runtime-cost.
I made a small example program that uses the linker to wrap custom functions around malloc and free.
It keeps track of all alocations in a resizeable array and provides a function
Code: Select all
void deallocate_exit(int)
to exit the program.
It doesn't double-free anything and doesn't leak any memory from my tests.
It uses "-Wl,-wrap=malloc -Wl,-wrap=free" as LDFLAGS.
It also seems to work with smart pointers and new.

For now it searches the entire array for a free place or for the entry to free.
I'm sure you could optimise this by making separate buckets of allocations depending on the address.
Should I optimize this and make it into a library?
You do not have the required permissions to view the files attached to this post.
User avatar
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Level up: 16%
 
Posts: 17
Joined: 03 Jul 2020, 12:22
Gender: Not specified
Calculator(s):
MyCalcs profile
GitHub: nspiredev500

Re: ndless memory map

Unread postby Adriweb » 06 Jul 2020, 16:55

Hmm, good job :)

MyCalcs: Help the community's calculator documentations by filling out your calculators info!
MyCalcs: Aidez la communauté à documenter les calculatrices en donnant des infos sur vos calculatrices !
Inspired-Lua.org: All about TI-Nspire Lua programming (tutorials, wiki/docs...)
My calculator programs
Mes programmes pour calculatrices
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 79.7%
 
Posts: 14820
Images: 1131
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
MyCalcs profile
Twitter: adriweb
GitHub: adriweb

Re: ndless memory map

Unread postby nspiredev500 » 07 Jul 2020, 11:35

I measured the performance of my wrapper on my calculator.
Code: Select all
for (volatile uint32_t i = 0;i<1000000;i++) // so this doesn't get optimized out
{
   volatile void* p = malloc(10); // so this doesn't get optimized out
   free(const_cast<void*>(p));
}
The binary size overhead is 8K.
The time overhead is 2.56 milliseconds.
This is the best-case scenario, as the lookup time is almost instant.
But when the list is already filled with 1000 entries, searching through it becomes really slow:
Only 100000 iterations, 14 seconds slower with the wrapper.

So either you don't have many objects or I have to optimize this a little.

EDIT: I put allocations into buckets, now it's faster, but depends on the size of your allocations, the heap layout at the time and the granularity of the buckets
You do not have the required permissions to view the files attached to this post.
User avatar
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Level up: 16%
 
Posts: 17
Joined: 03 Jul 2020, 12:22
Gender: Not specified
Calculator(s):
MyCalcs profile
GitHub: nspiredev500

Re: ndless memory map

Unread postby parisse » 07 Jul 2020, 20:12

Sorry for responding a little late, but I don't think I need a custom malloc. Shutdown is called from a getkey call, it was not that hard to return a KEY_SHUTDOWN code there and propagate to the caller when possible, until main is reached. I also set a shutdown flag to true when propagation to upper frames was not possible (more precisely would be too complicated to implement), so that exit is called from a next getkey.
User avatar
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Level up: 89.4%
 
Posts: 3721
Joined: 13 Dec 2013, 16:35
Gender: Not specified
Calculator(s):
MyCalcs profile

Previous

Return to Native: Ndless, Linux, ...

Who is online

Users browsing this forum: ClaudeBot [spider] and 6 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1195 utilisateurs:
>1156 invités
>32 membres
>7 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)