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

Memory allocation error?

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



Joined: 07 Sep 2003
Posts: 46
Location: Manchester, UK

View user's profile Send private message

Memory allocation error?
PostPosted: Sun Jun 15, 2003 5:22 am     Reply with quote

MPLAB 6.22 & PCH 1.48 & PIC18F252

When I alter the size of an int8 array, the memory usage seems to be double what I expect i.e. increasing the declaration of the index by one causes the compiler to report back an extra 2 bytes used. This is a fairly large program using a large amount of the RAM space (1200 bytes in declarations), about 12 int8 arrays and one 2 dimensional int8 array. However, I need to use more RAM and I rapidly run out...

If I try to replicate the problem with a very simple program the error does not occur.

For commercial reasons I cannot post the whole program, so what I'm really asking is; has anyone else seen a similar problem and have any work-arounds? Or am I doing something really stupid?

Steve
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515257
R.J.Hamlett
Guest







Re: Memory allocation error?
PostPosted: Sun Jun 15, 2003 2:47 pm     Reply with quote

:=MPLAB 6.22 & PCH 1.48 & PIC18F252
:=
:=When I alter the size of an int8 array, the memory usage seems to be double what I expect i.e. increasing the declaration of the index by one causes the compiler to report back an extra 2 bytes used. This is a fairly large program using a large amount of the RAM space (1200 bytes in declarations), about 12 int8 arrays and one 2 dimensional int8 array. However, I need to use more RAM and I rapidly run out...
:=
:=If I try to replicate the problem with a very simple program the error does not occur.
:=
:=For commercial reasons I cannot post the whole program, so what I'm really asking is; has anyone else seen a similar problem and have any work-arounds? Or am I doing something really stupid?
:=
:=Steve
There can be/are problems with very large arrays. Look in the history of this board, for some examples. Generally, if going significantly above the number of entries supported on the smaller chips (128), it is worth considering manually allocating the storage yourself.
One obvious comment, is that the two dimensional array, will (of course), increase memory useage by the size of the other index for every extra value added.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515262
mcafzap



Joined: 07 Sep 2003
Posts: 46
Location: Manchester, UK

View user's profile Send private message

Re: Memory allocation error?
PostPosted: Sun Jun 15, 2003 4:16 pm     Reply with quote

Thanks for your input RJ.

I'm well aware of the limitations of the PIC family but rather hoped those were behind us with the advent of the 18 series, perhaps not. As I said, I tried a simpler program with only one variable, an int8 multi-dimensional, and the memory allocation was OK, but the fault seems to occur once a certain number of variables is exceeded - the problem is really that I can't so far replicate the fault with a simpler program, nor can I remove it by editing the real program. I'll keep hacking away for a while, then I will probably dive into self-allocation to expedite matters.

Steve
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515264
TSchultz



Joined: 08 Sep 2003
Posts: 66
Location: Toronto, Canada

View user's profile Send private message

RE: Re: Memory allocation error?
PostPosted: Mon Jun 16, 2003 7:18 am     Reply with quote

:=Thanks for your input RJ.
:=
:=I'm well aware of the limitations of the PIC family but rather hoped those were behind us with the advent of the 18 series, perhaps not. As I said, I tried a simpler program with only one variable, an int8 multi-dimensional, and the memory allocation was OK, but the fault seems to occur once a certain number of variables is exceeded - the problem is really that I can't so far replicate the fault with a simpler program, nor can I remove it by editing the real program. I'll keep hacking away for a while, then I will probably dive into self-allocation to expedite matters.
:=
:=Steve

I completed a project using a PIC18F452 and encountered very strange memory allocations with large arrays. After revieiwing the memroy assignments I found that the compiler was actuall incorrectly assigning some memroy areas. There were usually problems at the end of arrays, where other variables would be assigned the same locations. I also found some issues with arrays that crossed each of the 256 markers. These problems ocurred once I used more than half the available memory if my memory serves me correctly.

At first I thought it was a problem with arrays of structures, however after recoding everything to use a series of single dimensional arrays the problems still persisted.

These problems were not always ocurrring and were driving me crazy trying to debug my code. I finally resored to reserving most of the memory and manually assigning the locations for all the arrays and data structures.

After manually locating all my variables, I left the lower 128 bytes avialble to the compiler and reserved everything else, I was able to make code and memory structure changes without the strange errors I was encountering before. The only big problem is to remember to update the memory assignments if you change any of the arrays or structures, or variable types.

It is rather unfortunate I had to resort to this, automatic assignments was one of the things the compiler is supposed to do for us.

This may, or may not, be the cause of your problems however I would suggest you review all the memory assingments to make sure they are OK after each compile, especially if you see any strange behaviour.

Best of luck

-Troy
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515294
mcafzap



Joined: 07 Sep 2003
Posts: 46
Location: Manchester, UK

View user's profile Send private message

Re: RE: Re: Memory allocation error?
PostPosted: Tue Jun 17, 2003 1:36 am     Reply with quote

Thank-you, Troy. I did exactly what you did, manually assigned the variables and my 'out of of memory' problems disappeared too.
As you say, it's a pity the compiler has errors in this area. We can live with limitations as long as we know about them.
Steve
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515315
R.J.Hamlett
Guest







Re: RE: Re: Memory allocation error?
PostPosted: Tue Jun 17, 2003 3:29 am     Reply with quote

:=Thank-you, Troy. I did exactly what you did, manually assigned the variables and my 'out of of memory' problems disappeared too.
:=As you say, it's a pity the compiler has errors in this area. We can live with limitations as long as we know about them.
:=Steve
Yes. If you look back at the previous threads about this, you will find that this is the 'general' solution, for anything using much more than the old 128byte limit. It is an area, where the compiler has for a long time, 'claimed' to offer support for larger sizes, but still seems to have problems several months latter... :-(

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515317
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