Go to Post If this isn't filmed in a Tim Hortons then I'm going to be severely disappointed. - marshall [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 04-01-2004, 18:10
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
Malloc, etc...

Has anyone found a way to allocate memory for a type with MCC18.
I've only used the standard ways around malloc like static variables and arrays to get pointers to create a list of pointers. I'll have to look into this more, but I was wondering if anyone knew off the top of their head, maybe an assembly trick or something. If no one knows how I'll just try to find out, there seems to be a lot of memory setting for strings.

Oh yeah, I couldn't find malloc or calloc, it's driving me crazy, C WITH NO MALLOC AAAAAAAAAAAAH!

Thanks,
Ryan Waliany
__________________
R
  #2   Spotlight this post!  
Unread 04-01-2004, 18:31
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
Re: Malloc, etc...

the documentation on this can be found in the following document:
http://microchip.com/download/tools/...b18/51288b.pdf
__________________
1139 Alumni
  #3   Spotlight this post!  
Unread 04-01-2004, 18:52
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
Re: Malloc, etc...

Quote:
Originally Posted by Rickertsen2
the documentation on this can be found in the following document:
http://microchip.com/download/tools/...b18/51288b.pdf
Thanks for the link, but can the documentation be found there? If so, I don't see it. They tell you how to use strings, etc... But they do not show you how they're memory allocation for their strings work. I suppose they don't except anyone to use it, so they didn't explain how?

I'm talking about like

typedef struct ptr PTR;

typedef struct
{
int value;
PTR *next, *prev;
} ptr;

.....code
PTR *temp;

how to create memory that is not deleted after the function is executed besides a static declaration, or a global declaration of an array.

I would like to know how to do like , temp = (PTR*)malloc(sizeof(PTR));
__________________
R
  #4   Spotlight this post!  
Unread 04-01-2004, 18:57
Rickertsen2 Rickertsen2 is offline
Umm Errr...
None #1139 (Chamblee Gear Grinders)
Team Role: Alumni
 
Join Date: Dec 2002
Rookie Year: 2002
Location: ATL
Posts: 1,421
Rickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant futureRickertsen2 has a brilliant future
Send a message via AIM to Rickertsen2 Send a message via Yahoo to Rickertsen2
Re: Malloc, etc...

I could have sworn there is a section on memory allocation in there somewhere. I think i recall readign this somewhere in the above document.
__________________
1139 Alumni

Last edited by Rickertsen2 : 04-01-2004 at 19:01.
  #5   Spotlight this post!  
Unread 05-01-2004, 01:28
JimWright949's Avatar
JimWright949 JimWright949 is offline
The Owen Day of Seattle
AKA: Jim Wright
FRC #4542 (Titanium Talons)
Team Role: Mentor
 
Join Date: Sep 2003
Rookie Year: 2003
Location: Redmond, WA
Posts: 94
JimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to behold
Re: Malloc, etc...

Ryan,

As a firmware developer by trade, we don't tend to use malloc in real embedded applications. The trouble is that there just isn't room for linked lists and other non-static memory uses.

If you need a list I would suggest a global queue or stack of a static size (10 to 20 items [or even an array]). This is to ensure other parts of your application get the memory they need. Now to get into the data hiding aspect that you probably want, make a few accessor functions to this global item (GetValue and PutValue) that handle talking to the global structure.

The reason for this is that the stack needs to be protected and if a link list goes wrong it could corrupt all sorts of memory. Another reason is that embedded applications just don't have the memory management code in them to handle malloc and free.

-Jim Wright
  #6   Spotlight this post!  
Unread 05-01-2004, 02:01
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Malloc, etc...

Quote:
Originally Posted by rwaliany
Oh yeah, I couldn't find malloc or calloc, it's driving me crazy, C WITH NO MALLOC AAAAAAAAAAAAH!
Ryan,

Just to amplify what Jim said, malloc() is really, really evil for small, embedded systems. It's a better practice to allocate all memory at run time (the stack is a special case) so that you are guaranteed to live (execute) within your means. For many reasons (e.g., fragmentation), memory managment without a real hardware memory managment unit (MMU) is a really tough problem. The size of the stack can be tweaked by initializing the stack to a fixed value (not zero) at runtime (see _startup() in ifi_startup.c), exercising all aspects of your code, and then examining the stack space to see where the "high water mark" is located. If you see that you came really close to using all of the stack space, you can allocate more at run time. Conversely, if you have a bunch of unused stack, you can free up some of that memory for other uses.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #7   Spotlight this post!  
Unread 05-01-2004, 02:18
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
Re: Malloc, etc...

Thanks, very helpful.
__________________
R
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


All times are GMT -5. The time now is 06:24.

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