Go to Post My mom's cousin heard from her friend who heard from her brother who heard from his barber who heard from his son that his teacher told him that his father's brother's sister's former roommate heard from Frank himself. - notmattlythgoe [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 12-02-2008, 01:05
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Dynamic Memory Allocation Woes

Hello,

For hybrid, we're using encoders on our drive train as well as various other sensors to place ourselves on an imaginary (x,y) coordinate grid on the field.

I have created code that allows you to store a list of points. It consists of a structure with two values (x and y) as well as a pointer to point to the next structure of the same type.

Basically, coodrinates are inserted into the heap using dynamic memory allocation (using the malloc funciton). Using the functions I created, these lists are then strung together using pointers. Using pointers, you can insert another block between two blocks in the list (say if we have to navigate around something) or delete blocks.

Look at my code for details. I've commented it as best I can.

I have seen this type of data structure called either Link Listing or Memory Blocks.

All of my code has been taken almost line-for-line by How to Program C by H.M. Deitel and P.M. Deitel, with a few cosmetic changes.

My problem is that despite including stdio.h and stdlib.h, the compiler claims that the funcion malloc does not exist, giving me the "use of function without prototype" and then an entire slew of errors.

Upon further inspection, I found that the default stdlib.h and stdio.h don't even contain a function prototype for malloc!

I am using MPLAB

Is there something I'm missing? Any help would be Greatly appreciated. My code is attached to this post.

EDIT: After searching a bit I found this. Can I use this in the way I want to?
Attached Files
File Type: h LinkList.h (903 Bytes, 65 views)
File Type: c LInkLIst.c (2.6 KB, 69 views)
__________________

Last edited by slavik262 : 12-02-2008 at 01:11. Reason: Found something!
  #2   Spotlight this post!  
Unread 12-02-2008, 01:43
jgannon's Avatar
jgannon jgannon is offline
I ᐸ3 Robots
AKA: Joey Gannon
no team
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Pittsburgh, PA
Posts: 1,467
jgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond repute
Re: Dynamic Memory Allocation Woes

You should probably read this post before you think any more about dynamic memory allocation.

http://www.chiefdelphi.com/forums/sh...87&postcount=6
__________________
Team 1743 - The Short Circuits
2010 Pittsburgh Excellence in Design & Team Spirit Awards
2009 Pittsburgh Regional Champions (thanks to 222 and 1218)
2007 Pittsburgh Website Award
2006 Pittsburgh Regional Champions (thanks to 395 and 1038)
2006 Pittsburgh Rookie Inspiration & Highest Rookie Seed

Team 1388 - Eagle Robotics
2005 Sacramento Engineering Inspiration
2004 Curie Division Champions (thanks to 1038 and 175)
2004 Sacramento Rookie All-Star

_
  #3   Spotlight this post!  
Unread 12-02-2008, 02:02
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Dynamic Memory Allocation Woes

I'm sorry I didn't do some more searching before I posted. Thank you very much. However, how would it be possible to use the stack for my purposes? The point is that I don't want to have a fixed number of my memory blocks, which unless there's a way I'm not thinking of, is impossible in stack memory.
__________________
  #4   Spotlight this post!  
Unread 12-02-2008, 02:06
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
Re: Dynamic Memory Allocation Woes

You could probably implement a faux "malloc"... you would just need a huge array, and some managing functions. It shouldn't be that difficult to do, you need to avoid issues such as fragmentation if you overuse it.

It is totally possible in stack memory, as stack memory is no different from heap memory... it's just a list of bits.
-Salik
__________________
Team 701
  #5   Spotlight this post!  
Unread 12-02-2008, 03:47
jgannon's Avatar
jgannon jgannon is offline
I ᐸ3 Robots
AKA: Joey Gannon
no team
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Pittsburgh, PA
Posts: 1,467
jgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond reputejgannon has a reputation beyond repute
Re: Dynamic Memory Allocation Woes

Quote:
Originally Posted by slavik262 View Post
The point is that I don't want to have a fixed number of my memory blocks
The thing is, you *do* have a fixed amount of memory, because of the limitations of the hardware. This isn't like the 4GB address space you're used to on a PC. I think you're far better off taking a static block of memory that is as big as you'll ever use, and build your data structure in there. It's not like you have to share your memory with other applications. I really can't think of anything that you could feasibly do with dynamic memory on the IFI controller that you couldn't also do with static memory, and it seems like you'd save yourself a huge pain in the process.
__________________
Team 1743 - The Short Circuits
2010 Pittsburgh Excellence in Design & Team Spirit Awards
2009 Pittsburgh Regional Champions (thanks to 222 and 1218)
2007 Pittsburgh Website Award
2006 Pittsburgh Regional Champions (thanks to 395 and 1038)
2006 Pittsburgh Rookie Inspiration & Highest Rookie Seed

Team 1388 - Eagle Robotics
2005 Sacramento Engineering Inspiration
2004 Curie Division Champions (thanks to 1038 and 175)
2004 Sacramento Rookie All-Star

_
  #6   Spotlight this post!  
Unread 12-02-2008, 10:27
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Dynamic Memory Allocation Woes

One other thing that we've found over the years is that pointer arithmetic on the RC processor is extremely costly. You may want to look at the .lst file that is generated when you build to see how much assembly is generated for pointer operations that you wouldn't bat an eye at on a desktop computer.

You may be better off storing an array of points as opposed to a linked list. If your points are sequential, there's no need to keep anything other than a simple index variable. If you're going to jump around inside the array, you'll need at least a second variable to index to your next point.
  #7   Spotlight this post!  
Unread 12-02-2008, 10:49
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,187
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Dynamic Memory Allocation Woes

I would use an array or shove the coordinates in the EEPROM. It takes a bit to read, but you can queue up values as you do other things. I'd probably make my "stack" 3 objects deep. (No calculated reason, just seems right to me.. )
  #8   Spotlight this post!  
Unread 12-02-2008, 16:15
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: Dynamic Memory Allocation Woes

Thanks to everyone for the help. A few responses:

Yes, I realize that I am using a fixed amount of memory regardless. My main concern was being able to insert points within my list, as opposed to having a set sequence of points. I suppose this could be done with a three-dimensional array. The first two dimensions could hold my coordinates, and the third dimension could determine which indice of the array comes next. If I really want, I could also use some bitwise with the upper digit of the third value to determine if that array indice is in use.

Thanks for the ideas

Slavik
__________________

Last edited by slavik262 : 12-02-2008 at 16:22.
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
Random Allocation of Trackballs fabalafae Rules/Strategy 7 07-01-2008 09:31
Please help: Memory allocation problem dealing with sections RbtGal1351 Programming 10 14-03-2006 14:58
Animation Woes Team905Animator 3D Animation and Competition 1 15-02-2005 16:34
Transmission Woes Madison Motors 3 19-02-2002 10:06
Gear Woes Simon G Technical Discussion 14 24-01-2002 16:31


All times are GMT -5. The time now is 19:12.

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