NXC command FreeMemory()

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

NXC command FreeMemory()

Post by mattallen37 »

Does the FreeMemory() command return the number of bytes in RAM that are available? If so, is there a command that returns the amount of available flash? Thanks.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nxtreme
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: NXC command FreeMemory()

Post by nxtreme »

Now, I'm not a NXC programmer but even I know how to use the search function over at the NXC help page (http://bricxcc.sourceforge.net/nbc/nxcd ... index.html). Type in 'freememory' and you'll get a great explanation and a sample program. Try it! When I tried to search for 'flash' it didn't come up with anything. Someone with more NXC experience will be able to explain better.
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC command FreeMemory()

Post by mattallen37 »

As I said, I know you aren't, but (as I also already said), the search doesn't work for me.

Edit: I figured it out, but it looks like it is for flash, not RAM.

I would like to know how to read both, so if you know how, please tell me.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC command FreeMemory()

Post by afanofosc »

There isn't any way provided by the standard NXT or enhanced NBC/NXC firmwares to find out how much RAM is available.

I would encourage you to show what you have figured out on your own by using the help and guide when you post a question. It will help other newcomers to NXC (and other programming languages) learn "how to fish" as it were. :-)

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC command FreeMemory()

Post by mattallen37 »

So basically, a program can crash because the NXT was overloaded, but there is no way to detect that ahead of time?

So, just to confirm, the command is for reading the remaining flash, and it is the number of bytes remaining?

I'll try to remember to post what I already learned and tried when I ask questions in the future. Thanks for answering.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC command FreeMemory()

Post by mightor »

First search result in Google:

Image

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC command FreeMemory()

Post by afanofosc »

mattallen37 wrote:So basically, a program can crash because the NXT was overloaded, but there is no way to detect that ahead of time?

So, just to confirm, the command is for reading the remaining flash, and it is the number of bytes remaining?
I will look into adding the ability to check how much RAM is available in a running program to the enhanced NBC/NXC firmware. I'll also look into exposing the "compact memory" option that the firmware has so that it can be executed manually by a running program. It is supposed to do that automatically whenever you try to allocate more memory for an array but it might be worth having the ability to do it on demand.

As the help files state, FreeMemory returns the number of bytes of flash memory that are free.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC command FreeMemory()

Post by mattallen37 »

So, why does it return numbers no more than 106.644 kB? Does the firmware REALLY take up over half the flash? The AT91SAM7S256 has 256 kB of flash, so if I am only seeing less than half that, what is using up all the rest? I know that I have the program to read that number on it, but that only exists of the following.

Code: Select all

task main()
{
  NumOut(0, LCD_LINE1,FreeMemory()); //106644 bytes is the MAX with this program
  while(true);
}
This small program can't take up much space.

Edit: the compiled program is 340 bytes, so REALLY small.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC command FreeMemory()

Post by mightor »

The firmware is indeed just under 128K, the max limit of the IAR workbench for ARM (free, size limited version).

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC command FreeMemory()

Post by mattallen37 »

Then where did the rest go?

256000 (total)
- 128000 (FW)
- 000340 (program)
- 106644 (remaining)
=022016 bytes that are... lost? 22kB is a significant amount when talking about the NXT, and the programs.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests