Comparing memory with a constant

I

Ian Malone

galapogos said:
Yes I know that's the worst case scenario that would work. I was just
hoping there was an easier way that I can implement the switch/case
statements rather than using a bunch of if-else statements that I'm
currently doing.

Hashtable?
 
G

galapogos

Ian said:
Hashtable?

Could you elaborate? I know the concept of a hashtable but I don't have
much experience with it and I don't see how it relates to the problem.
Are you saying each pattern will hash into the table and hopefully no
collisions will take place? Some kinda example would be great...thanks!
 
G

galapogos

Richard said:
galapogos said:



Who knows? It doesn't have to, as the code stands. All it *has* to do is
complain that you haven't provided enough argument expressions to memcmp.

Once you've fixed that, then yes, of course the compiler will store the
information you will need for your runtime comparison, and yes, of course
that will occupy some memory, so therefore the compiler will have to
allocate some memory for it to occupy.

Everything Has To Be Somewhere.

Thanks, I guess I should've known, since such large constants won't fit
into the literal/immediate field of any instruction set architecture
anyway. I was asking because I'm programming for an embedded system so
memory is kinda valuable.
 
I

Ian Malone

galapogos said:
Could you elaborate? I know the concept of a hashtable but I don't have
much experience with it and I don't see how it relates to the problem.
Are you saying each pattern will hash into the table and hopefully no
collisions will take place? Some kinda example would be great...thanks!

If you want to be able to do switch on these numbers then I guess
you have a finite manageable number of them and they are known
at compile time. Come up with some type of preprocessor which
converts your bit patterns to valid case labels, and make the
argument to the switch statement a call to a C function which
does the same hash.

This is basically Galapogos's proposal, although his suggested
'program P' would also try to analyze the set of bit patterns
you use to produce the most efficient outcome, and could be
used when the number of bit patterns exceeds the range
representable by an operand to switch. However if you have
that many of them a switch statement would be a bit absurd.
 
K

Keith Thompson

galapogos said:
Thanks, I guess I should've known, since such large constants won't fit
into the literal/immediate field of any instruction set architecture
anyway. I was asking because I'm programming for an embedded system so
memory is kinda valuable.

And even if they do, literal/immediate instruction fields take up
space too.

But if you're using an embedded system where RAM is scarce and ROM is
cheap, it *is* entirely possible that the compiler will put your
string literal in ROM. The standard doesn't say anything about this,
so if you want more information you'll have to try it yourself or ask
in a system-specific forum.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top