What does it mean to "allocate" memory? I've done it before (in C/C++), I kind of know what it means, but I want to know what's really going on. Does allocating memory mean taking it from the RAM and putting it somewhere where the user can control it? If that is the case, then how come in Z80 assembly it is possible to do something like ld hl,$1423 \ ld (hl),a without allocating memory? What is the Z80 assembly code to allocate memory? Is it possible to use functions like memcpy() (probably something like lddr to copy memory) to copy allocated memory to/from non-allocated memory? Can a pointer point to allocated memory? I'm just full of questions about this subject.
Well, if you're using user RAM (a.k.a. greater than or equal to $9D95) you can use the delmem and insertmem bcalls to delete memory and insert memory. If you're using the "saferam" like appbackupscreen and savescreen and stuff like that, you can just load freely into that.
allocating RAM is a call to the OS to give the program some RAM space. This isn't implemented in the TI calculators because there isn't really a need. There are instead predefined places that are "safe" (called saferam), and other means to get RAM (such as using space in the program itself, or creating an appvar) And since only one program can be running at a time (in general), the predetermined saferam areas are known to the programmer to be OK to use

the *alloc() C/C++ calls, however, do something slightly more than just asking for RAM. The OS also notes such calls, and how much (and where) the memory was allocated, so that it can then delete it if dealloc is called on it or if the program terminates, so that RAM isn't being permanently "in use"

While you technically CAN just start using RAM, it is a very, very bad idea (both on the calculator and on the PC). If you use RAM that is already in use (which would happen a majority of the time), you will RAM clear your calc. On a PC, anything could happen, but the OS will likely notice it and kill the process.
you should also make sure your programs don't interfere with the saferam areas used by your targeted shell, both DCS and MOS have certain areas you shouldn't use, but it doesn't matter unless you use calls specific to that shell.
If you want a really, really rough analogy, malloc() ~= _insertmem, and free() ~= _delmem. The analogy fails in many aspects, however.
KermMartian wrote:
If you want a really, really rough analogy, malloc() ~= _insertmem, and free() ~= _delmem. The analogy fails in many aspects, however.


doesn't _insertmem and _delmem only work if you already have a structure of some sort already created? (list, appvar, etc...)
Not at all. You can totally insertmem and delmem random chunks of memory, although it's nto really recommended.
are you sure? The 83psysroutines.pdf thing specifically states that InsertMem bcall "Inserts RAM into an existing variable.", and the example, of course, shows it using an appvar
Of course. You can [safely] feed it any memory location >$9d95, however, as demonstrated by Doors CS's swaploader for ASM programs.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement