Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Micromite Beta 10
Page 4 of 4 | |||||
Author | Message | ||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3196 |
If you used DIM Buffer$(4096) LENGTH 1 each element would use two bytes (one for the length and one for the character) so your buffer would use 8K. Another way around it would be to use DIM Buffer(1024) which will allocate 4K (each float is 4 bytes) and then use PEEK to walk up the variable table to find Buffer. The structure of each entry in the variable table is: char name[32]; // variable's name char type; // its type (T_NUM or T_STR) char level; // its subroutine or function level short int dims[8]; // the dimensions if it is an array unsigned char size; // the number of chars for each element in a string array void *data; 'data' is a pointer to the memory allocated to the array (in little endian format). You can treat this memory as a block of general purpose RAM for your own use. You can make it easy if DIM Buffer(1024) is the first thing in your program as you would not have to walk the variable table. For example, this will get a pointer to the buffer: Dim Buffer(1024) ' first variable referenced in the program
hiword = Peek(VARTBL, 55) * 256 + Peek(VARTBL, 54) loword = Peek(VARTBL, 53) * 256 + Peek(VARTBL, 52) You can then use PEEK and POKE to add and read data from the buffer. For example: POKE hiword, loword + head, char
or char = PEEK(hiword, loword + tail)
I can honestly say that this is one of only a few practical uses for PEEK/POKE that I have found. Geoff Geoff Graham - http://geoffg.net |
||||
Page 4 of 4 |
Print this page |