π
<-
Chat plein-écran
[^]

ndless memory map

C, C++, ASM...
En ligne

Re: ndless memory map

Message non lude parisse » 04 Juil 2020, 14:03

Exceptions are disabled when I compile giac for calculators, it would eat too much code space. The best way I can imagine to make "shutdown" cleaner is to alloc a large memory block at startup and have malloc/free work inside this bloc, then just before the exit() call one can free the large memory block. But it's really not my domain, it's more the job of ndless devs to do that and that would be useful for every ndless app. I think it's the solution that zardam is using for the Numworks external apps heap (I don't remember how exactly, something related to brk or mmap).
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude Adriweb » 04 Juil 2020, 14:12

It's not good practice to use manual memory management in modern C++ anyway - new/malloc ans delete/free shouldn't be used. Take a look at RAII and smart pointers instead for instance.
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.2%
 
Messages: 14614
Images: 1218
Inscription: 01 Juin 2007, 00:00
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
Twitter/X: adriweb
GitHub: adriweb

En ligne

Re: ndless memory map

Message non lude parisse » 04 Juil 2020, 14:36

I don't understand why you posted that. Nobody will rewrite large working pieces of code just because there is a new feature for memory management in a language. Moreover, in the end, the new language feature must allocate memory on the heap, and we are back to the same problem, how does it interact with exit()? I really believe that it should be the job of ndless to handle malloc/free in a way compatible with exit() and transparent for ndless app developers.
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude Adriweb » 04 Juil 2020, 14:44

I'm not saying that is has to be done for khicas, I know it would be too large of a refactor. It's rather more of a general advice for new developers making programs from scratch.
Also I don't think there's an issue at exit. The destructors will de-allocate the memory?
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.2%
 
Messages: 14614
Images: 1218
Inscription: 01 Juin 2007, 00:00
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
Twitter/X: adriweb
GitHub: adriweb

En ligne

Re: ndless memory map

Message non lude parisse » 04 Juil 2020, 14:49

No, because they will not be called by exit, unlike what happens when you leave the application with return in the main function.
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude Vogtinator » 04 Juil 2020, 15:08

On most modern OSs, processes have their own private address spaces, which allocation of memory ends up adding page mappings to.
This is what malloc/free are implemented on top of.

The Nspire OS does not support separate address spaces, everything is shared. While there are separate memory pools, they are fixed in size on startup, so we can't just add one for each program as there's no unused space in RAM. It would be possible to allocate a block of memory from the main pool and create a new pool out of that, but if programs use less or need more of that, it breaks. So that's not a solution either.

Most programs do proper memory ownership tracking, so this hasn't really been an issue yet.

No, because they will not be called by exit, unlike what happens when you leave the application with return in the main function.


Destructors of global objects are called by exit, but not others: https://en.cppreference.com/w/cpp/utility/program/exit
For complete cleanup, just throw a custom exception and catch it in main.
Avatar de l’utilisateur
VogtinatorPremium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Prochain niv.: 1.6%
 
Messages: 217
Inscription: 29 Mar 2014, 15:55
Genre: Homme
Calculatrice(s):
MyCalcs profile

En ligne

Re: ndless memory map

Message non lude parisse » 04 Juil 2020, 15:22

Vogtinator a écrit:For complete cleanup, just throw a custom exception and catch it in main.

But that means enable exceptions, and that would increase the size of khicas significantly, right?
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude Vogtinator » 04 Juil 2020, 15:34

But that means enable exceptions, and that would increase the size of khicas significantly, right?


That highly depends on the code, just try it out and see for yourself. I guess that the added unwind tables might be ~1-2% of the current executable's code size.
Avatar de l’utilisateur
VogtinatorPremium
Niveau 9: IC (Compteur Infatigable)
Niveau 9: IC (Compteur Infatigable)
Prochain niv.: 1.6%
 
Messages: 217
Inscription: 29 Mar 2014, 15:55
Genre: Homme
Calculatrice(s):
MyCalcs profile

Re: ndless memory map

Message non lude Adriweb » 04 Juil 2020, 15:42

Is there really any size issue on the Nspire though? Might be able to just enable exceptions with no impact anyway :p
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.2%
 
Messages: 14614
Images: 1218
Inscription: 01 Juin 2007, 00:00
Localisation: France
Genre: Homme
Calculatrice(s):
MyCalcs profile
Twitter/X: adriweb
GitHub: adriweb

En ligne

Re: ndless memory map

Message non lude parisse » 04 Juil 2020, 16:59

It's a 20% increase of the tns file: 4101544 -> 4890227. Not clear it's worth the increase size.
An alternative could be keep track of the auto-shutdown in the most comon situations where auto-shutdown may happen, that is a getkey call inside the shell or editor or sheet.
Avatar de l’utilisateur
parisseVIP++
Niveau 12: CP (Calculatrice sur Pattes)
Niveau 12: CP (Calculatrice sur Pattes)
Prochain niv.: 77.8%
 
Messages: 3511
Inscription: 13 Déc 2013, 16:35
Genre: Non spécifié
Calculatrice(s):
MyCalcs profile

PrécédenteSuivante

Retourner vers Native: Ndless, Linux, ...

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 14 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.
1508 utilisateurs:
>1481 invités
>22 membres
>5 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)