Go to Post Our team has a forum..... chiefdelphi.com Ok I had to say it. - Mike Martus [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-08-2009, 14:54
Cadyyan Cadyyan is offline
The Button Man
FRC #1716 (Redbird Robotics)
Team Role: Mentor
 
Join Date: Sep 2008
Rookie Year: 2007
Location: Wisconsin
Posts: 11
Cadyyan is an unknown quantity at this point
Dynamic memory MC18

How exactly do you dynamically allocate memory for an array in C? "New" is not a keyword and malloc does not seem to be included in the IFI library. There has to be a way to allocate memory. Isn't there?
~Cadyyan~
__________________
Watch your face!
  #2   Spotlight this post!  
Unread 18-08-2009, 16:27
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,082
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Dynamic memory MC18

To the best of my recollection, the PIC18 did not support dynamic memory allocation. You always have the option of declaring a big array at global scope and using that area as "scratch" for dynamic memory operations.

You could also dig up some EEPROM code and use that as your "dynamic" memory (Kevin Watson had written a nifty utility to read and write EEPROM). Just be aware that EEPROM is typically much slower than using the stack.

EDIT: I have checked and confirmed; the PIC does not support dynamic memory allocation.

Last edited by Jared Russell : 18-08-2009 at 16:37.
  #3   Spotlight this post!  
Unread 18-08-2009, 16:47
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: Dynamic memory MC18

Quote:
Originally Posted by Jared341 View Post
To the best of my recollection, the PIC18 did not support dynamic memory allocation.
It's not that the PIC18 won't support it, it's simply not implemented in any of the default libraries. It's not implemented because of limited system resources and the fact that it almost never makes sense to use dynamic allocation on a processor as small as a PIC. With that in mind, you might be able to find a 3rd party implementation, or you could certainly write your own.

To the original poster: I'd ask what you're trying to do that would use dynamic memory. Anything related to robot control should be well-enough understood in advance that you shouldn't need to dynamically allocate anything. You can likely rework your design to not need dynamic memory and be more efficient in the process.
Quote:
You could also dig up some EEPROM code and use that as your "dynamic" memory (Kevin Watson had written a nifty utility to read and write EEPROM). Just be aware that EEPROM is typically much slower than using the stack.
Yikes, I wouldn't do that. EEPROM has a limited number of write cycles before it wears out. It's meant for long-term storage of data, not random-access while a program is running. Plus, "typically much slower" is a large understatement. Writing to EEPROM can easily be 1,000,000x slower than writing to RAM (yes, that's 1 million times slower).
  #4   Spotlight this post!  
Unread 18-08-2009, 17:15
Cadyyan Cadyyan is offline
The Button Man
FRC #1716 (Redbird Robotics)
Team Role: Mentor
 
Join Date: Sep 2008
Rookie Year: 2007
Location: Wisconsin
Posts: 11
Cadyyan is an unknown quantity at this point
Re: Dynamic memory MC18

Well thanks. I think the best I could do would be to either make an array that "should" be large enough or else write a bunch more code for different scenarios. Thanks again for the responces.
__________________
Watch your face!
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Memory Allocation Woes slavik262 Programming 7 12-02-2008 16:15
Dynamic Tables in PHP FRANK(WGH) Website Design/Showcase 12 09-07-2007 16:07
Dynamic Debugging Tool MarkVH Programming 5 04-02-2005 18:09
Dynamic Linking with PHP plutonium83 Website Design/Showcase 6 12-01-2005 19:41
Dynamic Input/Output Changing Paolo Control System 6 23-09-2004 19:09


All times are GMT -5. The time now is 01:58.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi