# Memory Limit

**URL:** <https://forum.sierrawireless.com/t/memory-limit/4244>\
**Category:** Open AT\
**Created:** [February 27, 2010, 11:19pm UTC](https://forum.sierrawireless.com/t/memory-limit/4244 "2010-02-27T23:19:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dario72](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dario72](https://forum.sierrawireless.com/u/dario72)\
**Post date:** [February 27, 2010, 11:19pm UTC](https://forum.sierrawireless.com/t/memory-limit/4244/1 "2010-02-27T23:19:40Z")

</div>

Hi all,  
I’m working with a new Fastrack Supreme 20

I’d like to know how much memory can I allocate width the command

```
adl_memGet ( )

```

I’d like to know if, with it, I take memory from the heap o stack memory space,  
or if i take block from other memory space.

I’ve read that the modem has about 32M of RAM … I’d like to store serial data to  
it … is it possible ?

Thanks

Dario

---

<div class="post-metadata">

**Author:** ![charlvz](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@charlvz](https://forum.sierrawireless.com/u/charlvz)\
**Post date:** [March 1, 2010, 8:51am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/2 "2010-03-01T08:51:56Z")

</div>

> [@dario72](#):
>
> I’d like to store serial data

If you want to store data I would suggest using the Flash memory.  
If you want to Buffer the incomming data from the serial port for a short time the adl\_memGet function would work well.

For what reason are you storing data?

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 1, 2010, 9:06am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/3 "2010-03-01T09:06:59Z")

</div>

> [@charlvz](#):
>
> If you want to store data I would suggest using the Flash memory.

Flash is not suitable for rapidly-changing data; use the Flash only if you need to store it permanently.

> [@](#):
>
> If you want to Buffer the incomming data from the serial port for a short time the adl\_memGet function would work well.

Beware that dynamic allocation is often best avoided in embedded systems - why do you specifically want to use dynamic allocation?

Read the “Memory Service” section in the ADL User Guide for details of the dynamic allocation facilies provided by Open-AT.

> [@](#):
>
> For what reason are you storing data?

Good question!  
And what, exactly, do you mean by “store” - do you mean long-term, non-volatile storage (as charlvz seems to be assuming), or just short-term buffering?

---

<div class="post-metadata">

**Author:** ![charlvz](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@charlvz](https://forum.sierrawireless.com/u/charlvz)\
**Post date:** [March 1, 2010, 9:29am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/4 "2010-03-01T09:29:59Z")

</div>

Hi Awneil

> [@awneil](#):
>
> Beware that dynamic allocation is often best avoided in embedded systems

I don’t have much experience in memory allocation…Could you please explain why dynamic allocation should be avoided in embedded systems?

For a circular buffer for serial data, which of the following would you suggest:?  
ascii Buffer[1000]

or

ascii\* Buffer;  
Buffer = adl\_memGet(1000);

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 1, 2010, 10:22am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/5 "2010-03-01T10:22:38Z")

</div>

> [@charlvz](#):
>
> Could you please explain why dynamic allocation should be avoided in embedded systems?

The biggest single reason is: what will you do if your dynamic allocation request fails?

You must never simply assume at adl\_memGet (or wahtever) will “just work” - you must check the return value for success, and have some sensible recovery strategy when it indicates a failure.

On a desktop system, it is easy to just put up an error box saying, “insufficient memory” - but an embedded system can’t do that!

Other reasons are that it adds overheads, and introduces the risk of memory leaks.

> [@](#):
>
> For a circular buffer for serial data, which of the following would you suggest:?  
> ascii Buffer[1000]
> 
> or
> 
> ascii\* Buffer;  
> Buffer = adl\_memGet(1000);

Definitely the former.

You are asking for 1000 bytes of memory whichever way you do it: so you need to ensure that 1000 bytes of memory will always be available for that call - so you might just as well allocate it statically in the first place!

---

<div class="post-metadata">

**Author:** ![dario72](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dario72](https://forum.sierrawireless.com/u/dario72)\
**Post date:** [March 1, 2010, 6:57pm UTC](https://forum.sierrawireless.com/t/memory-limit/4244/6 "2010-03-01T18:57:20Z")

</div>

thanks … but do you know somethink about the memory limits ?

> [@awneil](#):
>
> > [@charlvz](#):
> >
> > If you want to store data I would suggest using the Flash memory.
> 
> Flash is not suitable for rapidly-changing data; use the Flash only if you need to store it permanently.
> 
> > [@](#):
> >
> > If you want to Buffer the incomming data from the serial port for a short time the adl\_memGet function would work well.
> 
> Beware that dynamic allocation is often best avoided in embedded systems - why do you specifically want to use dynamic allocation?
> 
> Read the “Memory Service” section in the ADL User Guide for details of the dynamic allocation facilies provided by Open-AT.
> 
> > [@](#):
> >
> > For what reason are you storing data?
> 
> Good question!  
> And what, exactly, do you mean by “store” - do you mean long-term, non-volatile storage (as charlvz seems to be assuming), or just short-term buffering?

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 2, 2010, 7:22am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/7 "2010-03-02T07:22:53Z")

</div>

> [@dario72](#):
>
> thanks … but do you know somethink about the memory limits ?

Have you actually looked in the ADL User Guide?

It tells you there how to determine the available memory…

---

<div class="post-metadata">

**Author:** ![chiduprakash](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@chiduprakash](https://forum.sierrawireless.com/u/chiduprakash)\
**Post date:** [March 2, 2010, 10:06am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/8 "2010-03-02T10:06:19Z")

</div>

What i suppose to do if i need 125K data size?

Currently i am using adl\_memget() function.

My application reading the data of meter which gives around 125K. This data will be sent once or twice in a month.

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [March 2, 2010, 10:09am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/9 "2010-03-02T10:09:05Z")

</div>

> [@chiduprakash](#):
>
> What i suppose to do if i need 125K data size?
> 
> Currently i am using adl\_memget() function.
> 
> My application reading the data of meter which gives around 125K. This data will be sent once or twice in a month.

i’d call that long-term storage.

but is that 125Kbyte per reading? or over the total of one month?

---

<div class="post-metadata">

**Author:** ![chiduprakash](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@chiduprakash](https://forum.sierrawireless.com/u/chiduprakash)\
**Post date:** [March 2, 2010, 10:14am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/10 "2010-03-02T10:14:52Z")

</div>

> [@](#):
>
> but is that 125Kbyte per reading? or over the total of one month?

It is instant reading not backup data of one month.

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 2, 2010, 10:40am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/11 "2010-03-02T10:40:36Z")

</div>

> [@chiduprakash](#):
>
> What i suppose to do if i need 125K data size?

Check your compiler (GCC?) manual for any specific limitations, but there’s no fundamental reason why you can’t statically-allocate a 125K-byte array.

> [@](#):
>
> Currently i am using adl\_memget() function.

And what would you do if that call fails?

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 2, 2010, 10:42am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/12 "2010-03-02T10:42:52Z")

</div>

> [@chiduprakash](#):
>
> It is instant reading not backup data of one month.

What - your meter gives 125K of data for one reading?! 😮

---

<div class="post-metadata">

**Author:** ![chiduprakash](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@chiduprakash](https://forum.sierrawireless.com/u/chiduprakash)\
**Post date:** [March 2, 2010, 11:12am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/13 "2010-03-02T11:12:51Z")

</div>

> [@awneil](#):
>
> What - your meter gives 125K of data for one reading?! 😮

Yes, that is 90 days data stored in meter. After giving single command it gives whole data thro Uart.

That is the requirement of customer whenever they want they can request this data.

---

<div class="post-metadata">

**Author:** ![chiduprakash](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@chiduprakash](https://forum.sierrawireless.com/u/chiduprakash)\
**Post date:** [March 2, 2010, 11:15am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/14 "2010-03-02T11:15:50Z")

</div>

> [@awneil](#):
>
> > [@chiduprakash](#):
> >
> > What i suppose to do if i need 125K data size?
> 
> Check your compiler (GCC?) manual for any specific limitations, but there’s no fundamental reason why you can’t statically-allocate a 125K-byte array.
> 
> > [@](#):
> >
> > Currently i am using adl\_memget() function.
> 
> And what would you do if that call fails?

I am using this application since 2 months i never noticed this fail.

Till now i not handling this exception.

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 2, 2010, 11:33am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/15 "2010-03-02T11:33:33Z")

</div>

> [@chiduprakash](#):
>
> I am using this application since 2 months i never noticed this fail.

So you have an obvious failure mechanism built into your application just waiting to bite you!

> [@](#):
>
> Till now i not handling this exception.

That is a really, really Bad Idea!

---

<div class="post-metadata">

**Author:** ![chiduprakash](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@chiduprakash](https://forum.sierrawireless.com/u/chiduprakash)\
**Post date:** [March 2, 2010, 11:54am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/16 "2010-03-02T11:54:44Z")

</div>

What is the final resort?

Shall i make static allocation?

Here is memory info from adl\_memGetInfo () of Q24+

Global Size=12282  
StackSize=3072  
HeapSize=1688582  
TotalSize=1703936

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 2, 2010, 12:53pm UTC](https://forum.sierrawireless.com/t/memory-limit/4244/17 "2010-03-02T12:53:56Z")

</div>

> [@chiduprakash](#):
>
> Shall i make static allocation?

That’s got to be the safest way unless you have some specific reason to use dynamic allocation.

---

<div class="post-metadata">

**Author:** ![blackyblack](https://avatars.discourse-cdn.com/v4/letter/b/2acd7d/32.png) [@blackyblack](https://forum.sierrawireless.com/u/blackyblack)\
**Post date:** [March 3, 2010, 6:05am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/18 "2010-03-03T06:05:29Z")

</div>

I’ve seen problems when making static allocation of large buffers. Something like 60 Kb is the limit. If using dynamic allocation the limit is much bigger, but after 300-400 Kb we encountered problems again (Q2686H and OASIS 7.4).

---

<div class="post-metadata">

**Author:** ![chiduprakash](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@chiduprakash](https://forum.sierrawireless.com/u/chiduprakash)\
**Post date:** [March 3, 2010, 6:29am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/19 "2010-03-03T06:29:28Z")

</div>

> [@blackyblack](#):
>
> I’ve seen problems when making static allocation of large buffers. Something like 60 Kb is the limit. If using dynamic allocation the limit is much bigger, but after 300-400 Kb we encountered problems again (Q2686H and OASIS 7.4).

maximum size u can allocate dynamically is u16 ie. 65536 bytes. If you want more u have to make multiple allocations.

–Edit–

Sorry i my OS version it is U16.  
Latest versions it is U32

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [March 3, 2010, 7:43am UTC](https://forum.sierrawireless.com/t/memory-limit/4244/20 "2010-03-03T07:43:52Z")

</div>

> [@blackyblack](#):
>
> I’ve seen problems when making static allocation of large buffers.

Could you elaborate on that?

> [@](#):
>
> Something like 60 Kb is the limit.

As noted by chiduprakash, if “something like 60K” is actually 64K - then that would indicate a 16-bit limitation somewhere.

Is it actually “something like” 60K bytes - or is it actually “something like” 60K elements in an array?

[Next page](https://forum.sierrawireless.com/t/memory-limit/4244.md?page=2)
