[TI ASM] Allocating memory.

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

[TI ASM] Allocating memory.

Post by benryves »

I was wondering the way people use to allocate RAM for use in their programs. For example, if you need an extra screen buffer, or otherwise (for example; Vinegar needs two 5KB-ish buffers).

I tend to create temporary programs and, after adding 2 to the returned data pointers, this seems to work quite well. If I need more speed, I'll calculate offsets into these programs and use a SMC-like approach to adjust the pointers in my program.

Of course, I pick silly names that shouldn't exist (Vinegar uses "ch8.tmpf" and "ch8.save" - lowercase) and delete the programs at the end.

Advantages of this are that the space is marked as being used, so other functions don't end up accidentally using this space. It does seem a bit messy, though...

Are there any better/cleaner methods?
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

I personally haven't used this method but there is rom call called Insertmem(opposite of delmem). It will insert memory into the ram so it won't effect other variables other than what it's inserting into. You could insert directly into end of your program. And since it shouldn't update you size bytes, you probably won't need to uninitialize.

However, i don't know if this exist for the 83(that's what you have right?). And i have never used it.
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Jim e wrote:I personally haven't used this method but there is rom call called Insertmem(opposite of delmem). It will insert memory into the ram so it won't effect other variables other than what it's inserting into. You could insert directly into end of your program. And since it shouldn't update you size bytes, you probably won't need to uninitialize.

However, i don't know if this exist for the 83(that's what you have right?). And i have never used it.
Ah, I never thought of that (I know _insertmem, but try to keep away from the editing ROM calls as some I've used in the past have been incorrectly documented). That's pretty damned clever, and you wouldn't even have to recalculate the pointers.

I have a regular 83+ :)
pacHa
Sir Posts-A-Lot
Posts: 190
Joined: Sun 09 Jan, 2005 9:51 am
Contact:

Post by pacHa »

I've used _enoughmem (see the Unification FAQ or Google cache since it seems to be down, section II.5)

mod edit: fixed urls to stop page from widening
Image
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

pacHa wrote:I've used _enoughmem (see the Unification FAQ or Google cache since it seems to be down, section II.5)
_enoughmem only checks free RAM after cleaning up all the temp variables, though... you still need to know where to put data?

EDIT: I should read better :) That approach looks to be the easiest, but I wonder what would happen if you used a ROM call that dealt with the memory..?
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

I'd say any method that creates variables is the best, since it won't mess up if the calc is shut off, or somehow directly exits to the homescreen. Then again, it won't matter if you're using a shell that doesn't keep memory correct (Ion).
You know your hexadecimal output routine is broken when it displays the character 'G'.
CompWiz
Calc King
Posts: 1950
Joined: Thu 13 Oct, 2005 1:54 pm
Location: UB

Post by CompWiz »

Unification FAQ
Google cache

HTML is disabled in this forum, but BBCode should work.
In Memory of the Maxcoderz Trophy Image
pacHa
Sir Posts-A-Lot
Posts: 190
Joined: Sun 09 Jan, 2005 9:51 am
Contact:

Post by pacHa »

thanks CompWiz :)

ben > Indeed it's easy to use, since I'm not a memory guru I can't answer about the effect of a ROM call dealing with memory though...

Dwedit > what happens to the free ram (reached by _enoughmem and then (FREE_MEM_START)) if the calc is shut down ? Is it flagged 'reserved' or something by the TI-OS ? If the program using free ram through this technique creates a new variable, is it possible that this new var is actually stored within that ram area ?


edit : it seems that paxl.org is up again :)
Image
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

pacHa wrote:If the program using free ram through this technique creates a new variable, is it possible that this new var is actually stored within that ram area ?
Yes, but the pointers will be changed too, so they are always safe to you as long as you don't mess with the variables manually (going around TIOS). I don't think any TIOS calls use the free RAM, they have all their data in the system RAM; that's why it is so big...
User avatar
Jim e
Calc King
Posts: 2457
Joined: Sun 26 Dec, 2004 5:27 am
Location: SXIOPO = Infinite lives for both players
Contact:

Post by Jim e »

Well, there are temp varibles and fps, but I doubt ben ryves is useing anything like that. I'm not certain it's wise to use un-allocated freemem now, it may change in the future. You now how kind TI likes to be with the community. tempvar is the sure thing, insertmem should work, though less often used(spencer uses this actually).
Image
Liazon
Calc Guru
Posts: 962
Joined: Thu 27 Oct, 2005 8:28 pm

Post by Liazon »

what exactly is memory allocation at the low level?
Image Image Image
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

I had put a set of memory management routines in the API, a few months ago. I never tested them though, and I'm unsure as to how they work, but perhaps they can give you some ideas :)
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

pacHa wrote:thanks CompWiz :)

ben > Indeed it's easy to use, since I'm not a memory guru I can't answer about the effect of a ROM call dealing with memory though...

Dwedit > what happens to the free ram (reached by _enoughmem and then (FREE_MEM_START)) if the calc is shut down ? Is it flagged 'reserved' or something by the TI-OS ? If the program using free ram through this technique creates a new variable, is it possible that this new var is actually stored within that ram area ?


edit : it seems that paxl.org is up again :)
(FREE_MEM_START is actually the floating point stack beginning, equivalent to the standard equate FPS, FREE_MEM_END is the operator stack OPS)
If you don't create any variables or anything else, the free mem region should be usable with no side effects, since it's not part of anything. The TIOS doesn't check if the values have changed and give less ram or anything like that.
If you create any variable, or use the floating point stack, or call a ti-basic program, then the pointers will change position, so your "free memory" area will move forward in memory. Your new var will be stored in what was previously "free memory", so if you touch the formerly free memory, you're messing with the new variable.
You know your hexadecimal output routine is broken when it displays the character 'G'.
pacHa
Sir Posts-A-Lot
Posts: 190
Joined: Sun 09 Jan, 2005 9:51 am
Contact:

Post by pacHa »

Dwedit, CoBB > ok thanks :)
Image
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

Liazon wrote:what exactly is memory allocation at the low level?
I think it is getting together enough free consecutive memory so that you you can store stuff there/execute it without worrying about having to jump to another block of memory. I think.
Image
Post Reply