π
<-
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 55 times
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 :)
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...)
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 80.2%
 
Posts: 14614
Images: 1218
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
Attachments
malloc-wrapper buckets.zip
(43.71 KiB) Downloaded 50 times
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

Online

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: 77.8%
 
Posts: 3511
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: No registered users and 7 guests

-
Search
-
Social TI-Planet
-
Featured topics
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
-
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.
1414 utilisateurs:
>1394 invités
>15 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)