Shop OBEX P1 Docs P2 Docs Learn Events
Array question — Parallax Forums

Array question

AImanAIman Posts: 531
edited 2012-07-04 16:20 in Propeller 1
I am curious on what people think -

What is the easiest way to do a "dynamic" array with a Prop?

Comments

  • Vega256Vega256 Posts: 197
    edited 2012-07-02 20:49
    This is one way, maybe not the easiest. Build a dynamic data table. Set aside a chunk of memory and a variable for your index and/or iterator. If you want to start with 5 elements, start at the first location and build up (If you want a LIFO structure, start at the last location and build down).
  • Mike GreenMike Green Posts: 23,101
    edited 2012-07-02 21:08
    Most of the standard I/O drivers do not use the upper portion of the HUB memory. The biggest exception is the graphics driver which is usually configured to have one or two screen buffers right at the end of HUB memory. Once upon a time, I had a Propeller OS that allocated work areas and buffers at the end of HUB memory by initializing a word to $8000 and decrementing this by the requested data area size before returning the resulting value (and storing it in the word used for it). This value was the start of the memory area to be used for the work area or buffer or array. You want to check this against the top of the run-time stack and leave some free stack area for the rest of the program to use, but that's the general scheme. There's no easy way to reuse the space, but, in this application, the allocated areas were always in use.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-07-03 07:15
    The CLIB object in the OBEX contains a heap manager. It is contained cmalloc.c. The mallocinit routine is called at the beginning of a program to initialize the heap and set a stack size for the top object. After that you can call malloc, calloc and free to allocate chunks of memory and free them.
  • prof_brainoprof_braino Posts: 4,313
    edited 2012-07-04 16:20
    AIman wrote: »
    I am curious on what people think -

    What is the easiest way to do a "dynamic" array with a Prop?

    Really, it can't be very dynamic, since there is a absolute max to the memory you can use. One technique is to cheat, use a couple buffers in RAM, and page them out to SD. Set the SD partitions (not files, but close enough) to the largest they are ever going to be, and start filling them up. I think Four buffers of 1K in Hub memory is the most we've needed so far.
Sign In or Register to comment.