View unanswered posts | View active topics It is currently Tue May 21, 2013 5:19 am






Reply to topic  [ 8 posts ] 
Memory handling in RobotC 
Author Message
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Memory handling in RobotC
Hi,

I'm just wondering whether you could delete variables in RobotC for memory allocation.
I am not very experienced at this and I would like to know because I have a very large array that may or may not cause the NXT to produce and error.


Mon Sep 24, 2012 3:59 am
Profile
Rookie

Joined: Thu Sep 13, 2012 9:43 am
Posts: 47
Post Re: Memory handling in RobotC
brianchen11 wrote:
Hi,

I'm just wondering whether you could delete variables in RobotC for memory allocation.
I am not very experienced at this and I would like to know because I have a very large array that may or may not cause the NXT to produce and error.


This might help viewtopic.php?f=1&t=500


Mon Sep 24, 2012 6:33 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1023
Post Re: Memory handling in RobotC
Talking about memory allocation, does RobotC 3.51 support dynamic memory allocation (i.e. the new and delete operator and heap)? I don't have RobotC in front of me, so I can't do tests to see if it supports it or not, nor can I look through the help topics to find the answer.


Mon Sep 24, 2012 12:41 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 537
Post Re: Memory handling in RobotC
MHTS wrote:
Talking about memory allocation, does RobotC 3.51 support dynamic memory allocation (i.e. the new and delete operator and heap)? I don't have RobotC in front of me, so I can't do tests to see if it supports it or not, nor can I look through the help topics to find the answer.


No - ROBOTC automatically handles the memory allocation of variables in your program. There are no malloc/free keywords in ROBOTC.

You have a 15K of Global Variables and around 5K of stack "dynamic" space that is shared with all declared tasks. Longs/Floats are 4 bytes, shorts are 2 bytes and chars/bytes are 1 - Strings are 20 bytes.

If you're looking at something incredibly complex and this won't be enough memory, you should look at using the IAR toolset with the NXT. Remember you're not programming on a PC with gigabytes of space and memory, but rather a small embedded processor - you should set your expectations as such.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Mon Sep 24, 2012 1:22 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1023
Post Re: Memory handling in RobotC
It is not really about anything complex or allocations that require GB of memory. At times when designing a module, there is a trade off of allocating a fixed size array and hope that you will never exceed the limit. Determining the size of the array at compile time is sometimes tricky. If you make it too big, you are wasting precious memory. If you make it too small, you may run out at run-time. Dynamically allocating memory doesn't always mean huge amount of memory, it is just deferring the allocation until run-time so that the exact amount of memory required is known. So far for our application, we haven't found a scenario where we absolutely require dynamic memory allocation (yet). But since 3.50 starts to support pointers, it is a logical question to ask whether it also supports dynamic memory allocation. So don't worry. I am not asking for that feature, just curious if it has the support :)


Mon Sep 24, 2012 1:41 pm
Profile
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: Memory handling in RobotC
I've used the array and it works for me:
byte coordinates[91][61];
This is a byte array as I don't need more than that.

Once I do get up to around [120][120] I get the error "Out of static memory for variable allocation."
but I don't need that much.


Tue Sep 25, 2012 3:02 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 2860
Location: Rotterdam, The Netherlands
Post Re: Memory handling in RobotC
120x120 bytes is very close to the 15k limit :)

- Xander

_________________
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)

| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Sep 25, 2012 3:23 am
Profile WWW
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Post Re: Memory handling in RobotC
So 15k is the limit.
I never knew that but I did know it was small.


Tue Sep 25, 2012 6:38 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.