π
<-
Chat plein-écran
[^]

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?
Attachments
malloc-wrapper.zip
(72.03 KiB) Downloaded 6 times
User avatar
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Level up: 62.5%
 
Posts: 9
Joined: 03 Jul 2020, 12:22
Gender: Not specified
Calculator(s):
GitHub: nspiredev500

Re: ndless memory map

Unread postby Adriweb » 06 Jul 2020, 16:55

Hmm, good job :)
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 54.5%
 
Posts: 12971
Images: 1087
Joined: 01 Jun 2007, 00:00
Location: France
Gender: Male
Calculator(s):
Class: (ingénieur)
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
Attachments
malloc-wrapper buckets.zip
(43.71 KiB) Downloaded 4 times
User avatar
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Level up: 62.5%
 
Posts: 9
Joined: 03 Jul 2020, 12:22
Gender: Not specified
Calculator(s):
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: 3.8%
 
Posts: 2065
Joined: 13 Dec 2013, 16:35
Gender: Not specified

Previous

Return to Native: Ndless, Linux, ...

Who is online

Users browsing this forum: No registered users and 8 guests

-
Search
-
Featured topics
L'OS 5.5 de la TI-83 Premium CE / 84 Plus CE supprime l'assembleur - la plupart des jeux et certains programme ne fonctionneront plus
Omega, le fork étendant les capacités de ta NumWorks, même en mode examen !
Découvre les nouvelles fonctionnalités en Python de l'OS 5.5 pour la 83PCE/84+C-T Python Edition
Comparaisons des meilleurs prix pour acheter sa calculatrice !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...

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.
681 utilisateurs:
>667 invités
>9 membres
>5 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)