| Author |
Message |
|
brianchen11
Rookie
Joined: Tue Jul 03, 2012 5:16 am Posts: 43
|
 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 |
|
 |
|
MikeJMcFarlane
Rookie
Joined: Thu Sep 13, 2012 9:43 am Posts: 47
|
 Re: Memory handling in RobotC
|
| Mon Sep 24, 2012 6:33 am |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 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 |
|
 |
|
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 537
|
 Re: Memory handling in RobotC
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 |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 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 |
|
 |
|
brianchen11
Rookie
Joined: Tue Jul 03, 2012 5:16 am Posts: 43
|
 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 |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2860 Location: Rotterdam, The Netherlands
|
 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 |
|
 |
|
brianchen11
Rookie
Joined: Tue Jul 03, 2012 5:16 am Posts: 43
|
 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 |
|
|