Compiler can save RAM doing this...

Post your requests and ideas on the future development of mikroC.
Post Reply
Author
Message
CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

Compiler can save RAM doing this...

#1 Post by CGEngineering » 09 Oct 2007 09:46

Hi,

i wrote a function to pass strings through USARTs (why does mikroC not integrate a function like this?), as it done by many mikroC users:

Code: Select all

void Usart_putstr1(char* sBuffer){
   unsigned char i;

   for (i=0; sBuffer[i]; i++) {
      if (sBuffer[i] == '\n')
         Usart_write1(13);  //return
         else Usart_write1(sBuffer[i]);
   }
}
that i can use like this:

Code: Select all

Usart_putstr1("This is how to save some RAM/n");
But i noted that passing strings like this wastes a lot of RAM. Can mikroC team improve that, in order to load strings between "..." in ROM?

Bye
CG

1jorgen
Posts: 24
Joined: 28 Sep 2007 23:27

#2 Post by 1jorgen » 10 Oct 2007 10:25

If you define the string as const, no RAM will be used to store the string.

E.g.

Code: Select all

void Usart_putstr1(const char* sBuffer)
--------------------------------------------------------------------
Do you speak assembly language? Yes, if it's to dark to c...

CGEngineering
Posts: 144
Joined: 09 May 2007 23:31
Location: Florence - Italy
Contact:

#3 Post by CGEngineering » 10 Oct 2007 19:48

1jorgen wrote:If you define the string as const, no RAM will be used to store the string.

E.g.

Code: Select all

void Usart_putstr1(const char* sBuffer)
Ok... but why do mikroC team do not include in their libraries something like this ?

Should i post in this thread my functions to send strings through Usart 232 and 485 half-duplex (or 232 with RTS)?... maybe they can copy&paste :)

Bye
CG

1jorgen
Posts: 24
Joined: 28 Sep 2007 23:27

#4 Post by 1jorgen » 10 Oct 2007 21:30

Ok... but why do mikroC team do not include in their libraries something like this ?
They have... the const keyword is a part of their C implementation and means in this case that characters are stored in flash. Wasn't that your original question?

Writing a wrapper of this kind is a 30 sec job. And you just have to do it once and keep it in your own private lib, so what's the problem?


/J
--------------------------------------------------------------------
Do you speak assembly language? Yes, if it's to dark to c...

Post Reply

Return to “mikroC Wish List”