CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

dynamically allocating memory!!!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fta
Guest







dynamically allocating memory!!!!
PostPosted: Tue Jul 26, 2005 3:41 am     Reply with quote

i was wondering how reliablly can memory be allocated dynamically. i am allocating about 62 bytes to a pointer to an array at the start of the program and then freeing up that memory space.
Code:
 char *array;
array =  calloc(62,1);
//at the end of the program

free(array);


now this code is working kind of on and off, some times it works but other times it doesnt. can any one suggest a better way for dynamic allocation or even any precautions.

also has any one used the watch dog timer for pic16f877a, if so then can you tell me how to use it
Ttelmah
Guest







PostPosted: Tue Jul 26, 2005 5:07 am     Reply with quote

First comment. If you are just allocating memory at the beginning, and clearing it at the end, using a fixed size, why bother?. The 'point' about dynamic memory, is if you need variable amounts, with different parts of the program having total demands that exceed the available 'pool'.
The main reason for problems is if anything changes ptr, or (obviously) if the code does not get to the de-allocation routine.
Remember also, that there is already a dynamic memory 'pool' directly implemented by the compiler. If you allocate a local variable, in a subroutine, when you leave that routine (provided the variable is not 'static'), the memory is available for re-use by the compiler.
There have been dozens of examples about the watchdog posted in the past. The 'point' of it, is that it allows you to ensure that if the processor hangs on a peripheral, or leaves the expected program 'path', a reset occurs. You have to program it with a timout interval, perhaps at least twice the gap between points in your program where you reset it (the oscillator involved is very inaccurate - at a 'nominal' 18mSec timeout, in some conditions of voltage/temperature, the actual timeout can be as low as 7mSec...). Then you have to ensure that if the program follows it's correct flow, and is running, 'restart_wdt' will be called often enough to prevent the timeout.

Best Wishes
UFAnders



Joined: 13 Apr 2005
Posts: 36
Location: Michigan

View user's profile Send private message Send e-mail Visit poster's website AIM Address

calloc(x,y) question
PostPosted: Mon Nov 21, 2005 10:38 pm     Reply with quote

I am trying to continue this thread avoid redundancy-->

I am trying to dynamically allocate a 2-dimensional array, one dimension being fixed. Here is my fixed structure size that will be an element within the array:
Code:
struct columnMAX7313
{
   int8 pixel[8];
} columnFillMAX7313,

Here is the statement I am using to create an expandable array of these:
Code:
dynamicFrame = calloc(numModules, 8);
dynamicFrame[0] = columnFillMAX7313;

numModules is filled in before the calloc() is reached in runtime, and the columnMAX7313 structure is 8 bytes large. I get a "Bad expression syntax" error when I compile. Why can't I insert these structures into areas that they should fit within? Shocked
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group