Question for xalloc

Started by "'Ya...@omniverter.com [rabbit-semi]" September 8, 2017
Hello,

I am using xalloc to get a block of memory for my data, my data is structure with many variables, roughly about 512 word, so after I read manual of xalloc, I should set 512x2 bytes memory for those data, but when I try to set 512 as memory size, I still can save those data without any problem, I would like to know why? And also I don’t understand sz explanation in the help below.

SYNTAX: long xalloc(long sz);

DESCRIPTION: Allocates memory in extended memory. If xalloc() fails,

a run-time error will occur. This is a wrapper function for _xalloc(),

for backwards compatibility. It is the same as

_xalloc(&sz, 1, XALLOC_MAYBBB)

except that the actual allocated amount is not returned since the parameter

is not a pointer. The returned address is always even (word) aligned.

NOTE: xalloc is not thread safe, since it accesses a global static structure

with no locking.

PARAMETER1: sz: The number of bytes to allocate. This is rounded up

to the next higher even number. ( what does it mean?)

RETURN VALUE: The 20-bit physical address of the allocated data.

KEYWORDS: xalloc, premain

YANG HONG

Application Engineer/Technical Support

Omniverter Inc.

3075 14th Avenue

Unit #13
Markham, Ontario
L3R 0G9 Canada

Tel: 416 849 2299

Direct: 647 874 1505
USA: 440 290 4499
Fax: 416 849 2298

Web: www.omniverter.com
When you call xalloc(), it reserves a portion of xmem for your use. If you go beyond the length of your allocation, you’ll overwrite something else in memory which will likely result in a crash at some point. Maybe you’re OK right now because nothing else is making use of that space, but you should fix your code to request the correct amount of space to save yourself headaches with future debugging!

The Rabbit doesn’t have a memory manager in place to throw a segmentation fault when you go outside of the requested memory range.

The “sz” parameter to xalloc() is the amount of space to reserve. In the _xalloc() call, you pass a pointer to a long with your desired allocation, and it will update that value with the actual amount of space reserved (which may be slightly larger than what you asked for).

Bottom line: If you ask for 512 bytes, don’t try to write past that 512-byte boundary.

-Tom
> On Sep 8, 2017, at 1:59 PM, 'Yang Hong' y...@omniverter.com [rabbit-semi] wrote:
> Hello,
>
>
>
> I am using xalloc to get a block of memory for my data, my data is structure with many variables, roughly about 512 word, so after I read manual of xalloc, I should set 512x2 bytes memory for those data, but when I try to set 512 as memory size, I still can save those data without any problem, I would like to know why? And also I don’t understand sz explanation in the help below.
>
>
>
>
>
> SYNTAX: long xalloc(long sz);
>
>
>
> DESCRIPTION: Allocates memory in extended memory. If xalloc() fails,
>
> a run-time error will occur. This is a wrapper function for _xalloc(),
>
> for backwards compatibility. It is the same as
>
> _xalloc(&sz, 1, XALLOC_MAYBBB)
>
> except that the actual allocated amount is not returned since the parameter
>
> is not a pointer. The returned address is always even (word) aligned.
>
>
>
> NOTE: xalloc is not thread safe, since it accesses a global static structure
>
> with no locking.
>
>
>
> PARAMETER1: sz: The number of bytes to allocate. This is rounded up
>
> to the next higher even number. ( what does it mean?)
>
>
>
> RETURN VALUE: The 20-bit physical address of the allocated data.
>
>
>
> KEYWORDS: xalloc, premain
>
>
>
>
>
>
>
> YANG HONG
>
> Application Engineer/Technical Support
>
> Omniverter Inc.
>
> 3075 14th Avenue
>
> Unit #13
> Markham, Ontario
> L3R 0G9 Canada
>
> Tel: 416 849 2299
>
> Direct: 647 874 1505
> USA: 440 290 4499
> Fax: 416 849 2298
>
> Web: www.omniverter.com
>
>
>
>
>
>