EmbeddedRelated.com
Forums

xalloc & xavail

Started by racar73 September 8, 2003
hi, i compile a sample programm in rabbit3000 128Kram 256flash:

main ()
{
int int_dimensione;
long ind_alloc;
long dimensione;
long indirizzo=0x0000;
long indirizzo_1=0x30000;

dimensione = xavail(indirizzo);
printf("\r\n spazio disponibile nella flash %x",dimensione);
ind_alloc =xalloc(dimensione);
printf("\r\n indirizzo allocazione %x",ind_alloc);
dimensione = xavail(indirizzo_1);
int_dimensione=(int)dimensione;
printf("\r\n spazio disponibile nella flash %x",dimensione);

}

have a result:
spazio disponibile nella flash
2e00
indirizzo allocazione
100
spazio disponibile nella flash
0

.......why change indirizzo and indirizzo_1 not change a result?
Gianluca




----------
> From: racar73 <racar@raca...>
> To: rabbit-semi@rabb...
> Subject: [rabbit-semi] xalloc & xavail
> Date: Monday, September 08, 2003 9:13 AM
>
>hi, i compile a sample programm in rabbit3000 128Kram 256flash:

>main ()
>{
>int int_dimensione;
>long ind_alloc;
>long dimensione;
>long indirizzo=0x0000;
>long indirizzo_1=0x30000;

>dimensione = xavail(indirizzo);
>printf("\r\n spazio disponibile nella flash %x",dimensione);

You should be doing "printf("\r\n spazio disponibile nella flash(??? not
RAM) %lx", dimensione);

>ind_alloc =xalloc(dimensione);
You just allocated every byte available for ind_alloc.

>printf("\r\n indirizzo allocazione %x",ind_alloc);
Change to printf("\r\n indirizzo allocatione %lx", ind_alloc);

>dimensione = xavail(indirizzo_1);
You either need a NULL pointer here or the address of a RAM variable.
Are warnings turned off? You should have got a warning about long and
void * being incompatible.
>int_dimensione=(int)dimensione;
>printf("\r\n spazio disponibile nella flash %x",dimensione);
Why the reference to flash? Sorry, I don't understand the rest of the
sentence. xalloc & xavail only operate on RAM.

}

>have a result:
>spazio disponibile nella flash
>2e00
You have a lot more than 0x2e00 bytes of RAM available
>indirizzo allocazione
>100

>spazio disponibile nella flash
>0
You got a zero because it was unable to allocate any memory. Your previous
allocation used every byte of xmem RAM available. I don't understand the
references to flash.

PS. Could someone with translating software re-post this? .......why change indirizzo and indirizzo_1 not change a result?
Gianluca
[Click Here!:
<http://us.a1.yimg.com/us.yimg.com/a/qu/quinstreet/300x250_uofp_green-arrows
2.gif>]
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
o?YH707890&yhad95053>
[<http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupma
il/S=:HM/A95053/randD0354237>]
To unsubscribe from this group, send an email to:
rabbit-semi-unsubscribe@rabb...
">http://docs.yahoo.com/info/terms/>.



>
> PS. Could someone with translating software re-post this?
>

main ()
{
int int_dimension;
long ind_alloc;
long dimension;
long address=0x0000;
long address_1=0x30000;

dimensione = xavail(address);
printf("\r\n available space RAM %x",dimension);
ind_alloc =xalloc(dimensione);
printf("\r\n allocate address %lx",ind_alloc);
dimensione = xavail(address_1);
int_dimension=(int)dimension;
printf("\r\n available space RAM %x",dimension);

} if change address and address_1 to NULL the resul is not change!!!!

I need a function calculate space free in ram and flash, a similar
malloc/free function.
thz
Gianluca


Maybe I misunderstand your question but:

The result of the xavail() function is the amount of available RAM
space (in bytes). Just check the doc:
xavail(): Returns the maximum length of memory that may be
successfully obtained by an immediate call to xalloc(), and
optionally allocates that amount.
The parameter passed is: Pointer to a long word in root data memory
to store the address of the block. If this pointer is NULL, then the
block is not allocated. Otherwise, the block is allocated as if by a
call to xalloc().

Note: this does NOT return the amount of free Flash space. No way to
check that, i think ...

So for your demo program:
- the first xavail() call will report the amount of free space and
does not allocate it (address = 0 and interpreted as a pointer).
- your call to xalloc() will allocate ALL available memory and
return the address of the allocated data area.
- your next call to xavail() will again report the amount of free
space which should be 0 now. You just allocated all available space
with xalloc().

The results you printf are not reliable. You should use %lx to print
a long not %x. Change that, and you will get normal results.

Why do you need to know the amount of free flash space???

Regards,
Rudi
www.x-graph.be the next generation Rabbit single board computer with
color lcd and touchscreen
--- In rabbit-semi@rabb..., "racar73" <racar@i...> wrote:
>
> >
> > PS. Could someone with translating software re-post this?
> >
>
> main ()
> {
> int int_dimension;
> long ind_alloc;
> long dimension;
> long address=0x0000;
> long address_1=0x30000;
>
> dimensione = xavail(address);
> printf("\r\n available space RAM %x",dimension);
> ind_alloc =xalloc(dimensione);
> printf("\r\n allocate address %lx",ind_alloc);
> dimensione = xavail(address_1);
> int_dimension=(int)dimension;
> printf("\r\n available space RAM %x",dimension);
>
> } > if change address and address_1 to NULL the resul is not change!!!!
>
> I need a function calculate space free in ram and flash, a similar
> malloc/free function.
> thz
> Gianluca




--- In rabbit-semi@rabb..., "Rudi" <yahoo@d...> wrote:
> Maybe I misunderstand your question but:
>
> The result of the xavail() function is the amount of available RAM
> space (in bytes). Just check the doc:
> xavail(): Returns the maximum length of memory that may be
> successfully obtained by an immediate call to xalloc(), and
> optionally allocates that amount.
> The parameter passed is: Pointer to a long word in root data memory
> to store the address of the block. If this pointer is NULL, then
the
> block is not allocated. Otherwise, the block is allocated as if by
a
> call to xalloc().
>
> Note: this does NOT return the amount of free Flash space. No way
to
> check that, i think ...
>
> So for your demo program:
> - the first xavail() call will report the amount of free space and
> does not allocate it (address = 0 and interpreted as a pointer).
> - your call to xalloc() will allocate ALL available memory and
> return the address of the allocated data area.
> - your next call to xavail() will again report the amount of free
> space which should be 0 now. You just allocated all available space
> with xalloc().
>
> The results you printf are not reliable. You should use %lx to
print
> a long not %x. Change that, and you will get normal results.
>
> Why do you need to know the amount of free flash space???


I need a function calculate space free in ram and flash( a similar
malloc/free function) for use in linked list for dynamic memory.
> Regards,
> Rudi
> www.x-graph.be the next generation Rabbit single board computer
with
> color lcd and touchscreen >
> --- In rabbit-semi@rabb..., "racar73" <racar@i...> wrote:
> >
> > >
> > > PS. Could someone with translating software re-post this?
> > >
> >
> > main ()
> > {
> > int int_dimension;
> > long ind_alloc;
> > long dimension;
> > long address=0x0000;
> > long address_1=0x30000;
> >
> > dimensione = xavail(address);
> > printf("\r\n available space RAM %x",dimension);
> > ind_alloc =xalloc(dimensione);
> > printf("\r\n allocate address %lx",ind_alloc);
> > dimensione = xavail(address_1);
> > int_dimension=(int)dimension;
> > printf("\r\n available space RAM %x",dimension);
> >
> > }
> >
> >
> > if change address and address_1 to NULL the resul is not
change!!!!
> >
> > I need a function calculate space free in ram and flash, a
similar
> > malloc/free function.
> > thz
> > Gianluca




--- In rabbit-semi@rabb..., "racar73" <racar@i...> wrote:
>

> > Why do you need to know the amount of free flash space??? > I need a function calculate space free in ram and flash( a similar
> malloc/free function) for use in linked list for dynamic memory.
>

Still don't understand why you need the amount of free flash space.
Free RAM is useable, Free flash is of no use.

malloc/free work on a RAM heap. This is a separate memory space than
code. Most OS's and embedded systems have no way of telling how much
code (read only) space is free.

If you were to find the amount of free flash space, what would you
possibly do with it? Yes, you could write to flash (dangerous), but it
would be much better to use a flash filesystem for that, especially
because it is pre-allocated at compile time.

<Scott


ok i use free ram :D
thz --- In rabbit-semi@rabb..., "shdesigns2003" <nospam@s...>
wrote:
> --- In rabbit-semi@rabb..., "racar73" <racar@i...> wrote:
> >
>
> > > Why do you need to know the amount of free flash space???
> >
> >
> > I need a function calculate space free in ram and flash( a
similar
> > malloc/free function) for use in linked list for dynamic memory.
> >
>
> Still don't understand why you need the amount of free flash space.
> Free RAM is useable, Free flash is of no use.
>
> malloc/free work on a RAM heap. This is a separate memory space than
> code. Most OS's and embedded systems have no way of telling how much
> code (read only) space is free.
>
> If you were to find the amount of free flash space, what would you
> possibly do with it? Yes, you could write to flash (dangerous), but
it
> would be much better to use a flash filesystem for that, especially
> because it is pre-allocated at compile time.
>
> <Scott>