2016-03-18 11:36:04 +00:00
|
|
|
{{DISPLAYTITLE:_MEMNEW}}
|
2017-10-10 14:55:21 +00:00
|
|
|
The [[_MEMNEW]] function allocates new memory and returns a [[_MEM]] memory block referring to it.
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
{{PageSyntax}}
|
2017-10-10 14:55:21 +00:00
|
|
|
: {{Parameter|memoryBlock}} = [[_MEMNEW]]({{Parameter|byteSize}})
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2021-02-28 14:47:33 +00:00
|
|
|
{{PageParameters}}
|
2021-01-24 03:36:34 +00:00
|
|
|
* The {{Parameter|byteSize}} parameter is the desired byte size of the memory block based on the variable [[Variable Types|type]] it will hold.
|
2016-03-18 11:36:04 +00:00
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
{{PageDescription}}
|
|
|
|
* The {{Parameter|memoryBlock}} value created holds the elements .OFFSET, .SIZE, .TYPE and .ELEMENTSIZE.
|
|
|
|
* [[_MEMNEW]] does not clear the data previously in the memory block it allocates, for speed purposes.
|
|
|
|
* To clear previous data from a new memory block, use [[_MEMFILL]] with a byte value of 0.
|
|
|
|
* When a new memory block is created the memory .TYPE value will be 0.
|
|
|
|
* '''If the read only memory block .SIZE is 0, the memory block was not created.'''
|
|
|
|
* '''All values created by memory functions must be freed using [[_MEMFREE]] with a valid [[_MEM]] variable.'''
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
{{PageExamples}}
|
|
|
|
''Example:'' Shows how [[SINGLE]] numerical values can be passed, but non-fixed [[STRING]] lengths cannot get the value.
|
2015-08-02 12:12:44 +00:00
|
|
|
{{CodeStart}} '' ''
|
|
|
|
{{Cl|DIM}} m {{Cl|AS}} {{Cl|_MEM}}
|
|
|
|
{{Cl|DIM}} f {{Cl|AS}} {{Cl|STRING}} * 5
|
|
|
|
m = {{Cl|_MEMNEW}}(5) 'create new memory block of 5 bytes
|
|
|
|
a = 12345.6
|
|
|
|
{{Cl|_MEMPUT}} m, m.OFFSET, a 'put single value
|
|
|
|
{{Cl|_MEMGET}} m, m.OFFSET, b 'get single value
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|PRINT}} "b = "; b
|
|
|
|
c$ = "Doggy"
|
2015-08-02 12:12:44 +00:00
|
|
|
{{Cl|_MEMPUT}} m, m.OFFSET, c$ 'put 5 byte string value
|
|
|
|
{{Cl|_MEMGET}} m, m.OFFSET, d$ 'get unfixed length string value
|
|
|
|
{{Cl|_MEMGET}} m, m.OFFSET, f 'get 5 byte string value
|
|
|
|
e$ = {{Cl|_MEMGET (function)|_MEMGET}}(m, m.OFFSET, {{Cl|STRING}} * 5) 'get 5 byte string value
|
2019-04-15 01:15:33 +00:00
|
|
|
{{Cl|PRINT}} "d$ = "; d$; {{Cl|LEN}}(d$) 'prints empty string
|
|
|
|
{{Cl|PRINT}} "e$ = "; e$; {{Cl|LEN}}(e$)
|
|
|
|
{{Cl|PRINT}} "f = "; f; {{Cl|LEN}}(f) '' ''
|
2015-08-02 12:12:44 +00:00
|
|
|
{{CodeEnd}}
|
|
|
|
{{OutputStart}}b = 12345.6
|
|
|
|
d$ = 0
|
|
|
|
e$ = Doggy 5
|
|
|
|
f = Doggy 5 {{OutputEnd}}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-10 14:55:21 +00:00
|
|
|
{{PageSeeAlso}}
|
2015-08-02 12:12:44 +00:00
|
|
|
* [[_MEM]], [[_MEMPUT]]
|
|
|
|
* [[_MEMGET]], [[_MEMGET (function)]]
|
2016-03-18 11:36:04 +00:00
|
|
|
* [[_MEMFILL]], [[_MEMFREE]]
|
2015-08-02 12:12:44 +00:00
|
|
|
|
|
|
|
|
2019-04-15 01:15:33 +00:00
|
|
|
{{PageNavigation}}
|