π
<-
Chat plein-écran
[^]

ndless memory map

C, C++, ASM...

Re: ndless memory map

Message non lude nspiredev500 » 06 Juil 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: Tout sélectionner
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?
Fichiers joints
malloc-wrapper.zip
(72.03 Kio) Téléchargé 53 fois
Avatar de l’utilisateur
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Prochain niv.: 16%
 
Messages: 17
Inscription: 03 Juil 2020, 12:22
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile
GitHub: nspiredev500

Re: ndless memory map

Message non lude Adriweb » 06 Juil 2020, 16:55

Hmm, good job :)
Image

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...)
Avatar de l’utilisateur
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Prochain niv.: 80%
 
Messages: 14599
Images: 1216
Inscription: 01 Juin 2007, 00:00
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
Twitter/X: adriweb
GitHub: adriweb

Re: ndless memory map

Message non lude nspiredev500 » 07 Juil 2020, 11:35

I measured the performance of my wrapper on my calculator.
Code: Tout sélectionner
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
Fichiers joints
malloc-wrapper buckets.zip
(43.71 Kio) Téléchargé 48 fois
Avatar de l’utilisateur
nspiredev500
Niveau 4: MC (Membre Confirmé)
Niveau 4: MC (Membre Confirmé)
Prochain niv.: 16%
 
Messages: 17
Inscription: 03 Juil 2020, 12:22
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile
GitHub: nspiredev500

Re: ndless memory map

Message non lude parisse » 07 Juil 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.
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.1%
 
Messages: 3497
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Précédente

Retourner vers Native: Ndless, Linux, ...

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 7 invités

-
Rechercher
-
Social TI-Planet
-
Sujets à la une
Comparaisons des meilleurs prix pour acheter sa calculatrice !
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
Phi NumWorks jailbreak
123
-
Faire un don / Premium
Pour plus de concours, de lots, de tests, nous aider à payer le serveur et les domaines...
Faire un don
Découvrez les avantages d'un compte donateur !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partenaires et pub
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
893 utilisateurs:
>866 invités
>23 membres
>4 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Autres sites intéressants
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)