Is it possible to have determine array size in runtime


Results 1 to 4 of 4

Threaded View

  1. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Is it possible to have determine array size in runtime

    Hi, What you’re talking about is what malloc (memory allocate) in C does.
    That’s intended for programs running under operating systems where other programs may be running,
    and already consuming memory. So your program asks the system for a quantity of memory,
    and a flag is returned if it was available.

    I doubt it’s implemented in C for microcontrollers because the function would consume considerable
    RAM and code space for many microcontrollers.

    When you declare an array in PBP or RISC asm, all the compiler remembers is to reserve the next
    memory spaces and mark the next variables in the locations following the array.
    Code:
    var byte array[20]
    var byte value
    In this case the variable “Value” will be permanently associated with RAM location 21,
    and any time the array is used, the index is added to the array start location.
    Code:
    array[10] = 1
    
    same as
    
    (*array + 10) = 1
    These numbers aren’t strictly true because PBP will put some of it’s own system variables before your array.

    If there’s only one possible big array to deal with I don’t see a reason not to simply make it as large as you can afford.
    If you don’t always use the maximum size of it, you can always mark the end with a normally unused character or sequence,
    and search for that to find the current array size you’re using.
    Last edited by Art; - 21st March 2016 at 16:54.

Similar Threads

  1. Changing CONFIG @ runtime possible ???
    By Acetronics2 in forum PBP3
    Replies: 2
    Last Post: - 8th April 2014, 19:47
  2. PIC16 Max Array Size
    By MikeWinston in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th February 2012, 17:30
  3. Configure Debug @ runtime?
    By dhouston in forum Serial
    Replies: 5
    Last Post: - 11th November 2011, 21:04
  4. Redefinition of CON bmode during runtime
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th February 2008, 22:57
  5. PIC18F4515 Serin2 Maximum Array size
    By millersamsr in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 6th April 2007, 00:29

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts