Subject:
|
NBC arrays
|
Newsgroups:
|
lugnet.robotics.nxt
|
Date:
|
Sun, 29 Apr 2007 00:55:02 GMT
|
Viewed:
|
18960 times
|
| |
| |
Is there some more detailed (and lower-level) description of how the arrays work
in NBC, please? Something that would complement the description in the manual?
This is how I see the arrays in NBC/standard firmware:
* a compiled program works with fixed number of top-level arrays, these are
referred by global variables, such as:
ar1 byte[]
* top-level arrays can contain sub-arrays, which can be allocated during the
runtime, and are also automatically deallocated when the top-level array shrinks
in size;
* top-level arrays have to be initialized either directly in data segment
ar1 byte[] 'hello'
or in the code dynamically as:
arrinit ar1, filling_value, size
Here is a first question: if the array variable already contained some value
(existing array), what does the arrinit do with this old value and with the
previously allocated memory?
My guess: it keeps the same memory space for the newly assigned array, and
simply overwrites it. If the memory block is not large enough, it is extended
(or moved somewhere else, perhaps)
* however, it is possible to acquire new top-level arrays in some other ways:
arrsubset new_array, src_array, src_index, count
here a part of src_array is copied to a newly created array, which is assigned
to new_array. My guess is that again the original memory for new_array is
re-used, and possibly made larger, if needed
replace new_array, src_array, src_index, new_value(s)
here the whole src_array is copied, and the value at src_index (or several
values starting at src_index) are replaced by new_value (or new_values, if it is
an array). the resulting array will again overwrite the memory used by
new_array.
is that right that the target array (new_array) in both of these calls does not
have to exist/be allocated before, or does it already have to have the proper
size? if it has larger/smaller size, is it automatically shrunk/extended?
Impression is that "newly created array"s concept for top-level arrays means
that the existing top-level arrays are resized as needed to fit the results of
the array operations, but new arrays are never allocated at top-level. Is that
right?
Or is it rather so that the memory is not reused, and new arrays in new memory
locations are created and the old values are just lingering around, slowly
filling up the memory? Or is there perhaps some kind of immediate garbage
collection of the unused blocks implemented?
Are the array operations completely general (if the element types are the same),
or should one avoid certain situations/combinations?
|
|
Message has 1 Reply: | | Re: NBC arrays
|
| (...) Perhaps the executable file and bytecode reference PDF explains arrays in a way that would complement the description in the NBC manual. The firmware source code is also a good source of information about how arrays work. (...) The firmware (...) (18 years ago, 4-May-07, to lugnet.robotics.nxt)
|
4 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|