π
<-
Chat plein-écran
[^]

ndless memory map

C, C++, ASM...

Re: ndless memory map

Unread postby parisse » 04 Jul 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).
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

Re: ndless memory map

Unread postby Adriweb » 04 Jul 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.
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 54.6%
 
Posts: 12973
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 parisse » 04 Jul 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.
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

Re: ndless memory map

Unread postby Adriweb » 04 Jul 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?
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 54.6%
 
Posts: 12973
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 parisse » 04 Jul 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.
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

Re: ndless memory map

Unread postby Vogtinator » 04 Jul 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.
User avatar
VogtinatorPremium
Niveau 8: ER (Espèce Rare: nerd)
Niveau 8: ER (Espèce Rare: nerd)
Level up: 58.6%
 
Posts: 160
Joined: 29 Mar 2014, 15:55
Gender: Male
Calculator(s):

Re: ndless memory map

Unread postby parisse » 04 Jul 2020, 15:22

Vogtinator wrote: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?
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

Re: ndless memory map

Unread postby Vogtinator » 04 Jul 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.
User avatar
VogtinatorPremium
Niveau 8: ER (Espèce Rare: nerd)
Niveau 8: ER (Espèce Rare: nerd)
Level up: 58.6%
 
Posts: 160
Joined: 29 Mar 2014, 15:55
Gender: Male
Calculator(s):

Re: ndless memory map

Unread postby Adriweb » 04 Jul 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
User avatar
AdriwebAdmin
Niveau 16: CC2 (Commandeur des Calculatrices)
Niveau 16: CC2 (Commandeur des Calculatrices)
Level up: 54.6%
 
Posts: 12973
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 parisse » 04 Jul 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.
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

PreviousNext

Return to Native: Ndless, Linux, ...

Who is online

Users browsing this forum: No registered users and 4 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.
679 utilisateurs:
>664 invités
>9 membres
>6 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)