String pooling in gcc with PROGMEM

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
My flash is really 99% used and I can save some 20KB
by using string pooling in A VERY IMPORTANT ;-) real-time system with interactive console (the strings are variable names, some 8...25 chars long (max 80 long)).
Of course all is using PROGMEM already.
Now the question is how to force it. I have found no option for that in gcc and it doesn't appears it is already done during compilation, even if I have several occurrences like:
VARNAME_A
VARNAME_A_MIN
a perfect scenario for suffix-based pooling.
So far I use PSTR macros but I can rewrite that easily.
Next step would be to put ALL strings (including error mesgs) to a pool.

I wonder if gcc can do this at all.
Anybody got custom codes for that?
I considered bit-rating strings at 6bits, but minor gain (only 25%).
Before I put LHA on it, would be nice to know what to try in an evening?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not have a string "VARNAME_A" and one "_MIN". That will achieve your pooling, won't it?

I really doubt that there is any way to get the compiler to create the pools.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Suffix based pooling is very difficult, because you don't know where to stop, as you can no longer rely on the null terminator. Prefix pooling is easier to implement. In either case you will need to do this manually.

Alternatively, you can look at doing some form of token based compression.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Why not have a string "VARNAME_A" and one "_MIN". That will achieve your pooling, won't it?

because there are ... 415 of them.
in many combinations, like OUTPUT_ INPUT_ MIXER_ etc.
Also I am looking for a general solution.
I am about to roll my own.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just tokenise them, and let your output routine expand the tokens.

If you have duplicate strings, you can expect these to be reduced to a single copy. But you will have to read a lot of documentation to see how. Or perhaps pre-process the generated code yourself.

It is very unlikely that anything will give two entry points for "Prentice" and "David Prentice". And no way could you get "David" as a separate string.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It reminds me gangsta movies: 'Yo TOKEN to me?'

What could be the name of the process when I need to extract all common tokens of length at least N from given
pool of stings? The complexity can be N^4, I don't care.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmm--Especially if the pool of strings is fixed (at least for a "run"), then a LEX-like state machine might be the fastest and might even be the smallest? (I guess the "smallest" might depend on the particular mix.) We used to do that on small microcomputers many years ago and it was the smallest way for sets of keywords.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.