Re: Library Design, f0dder's nightmare.
- From: "hutch--" <hutch@xxxxxxxxx>
- Date: 19 Jun 2006 06:16:13 -0700
I am pleased to see that you have fixed another mistake after the first
demo mistake but I suggest to you that a sequence of blunders on this
scale while using your example as a model of how other people should
design their code hasn't sold the case you wish to flog over time.
Now rather than trying to use flawed examples to criticise other
people's work, if you bothered to properly develop the algo you could
get something like reasonable results for a very old architecture like
argv - argc that would be popular with people who ant to use an old
architecture like this.
Using the stack may be easy in this context but its not good design as
the application that uses the algo needs to compensate for the unknown
stack offset. You can do a lot better with just a little simple
arithmetic.
A 32k command line can at the most have 16k of arguments, (1 character
and one delimiter so you dynamically allocate a 64k array to store
pointers. Feed it through your parser to get the offset of each
argument and overwrite the trailing delimiter with a zero. Write each
offset to its appropriate place in the array of pointers and when you
have finished the scan of the buffer, either original or a copy, you
reallocate the buffer size back down to the last member written to it
so you are not wasting memory.
You need to pass back 2 pieces of information, the argument count and
the pointer array offset. In assembler you would use two (2) registers
but if you need to use it from a high level language, you would
probably pass the address of a structure and write the two values to
it.
You can do it even smarter by testing the command line length, and
dividing the byte count by two to determine the maximum pointer array
size array so it uses even less memory.
This is not a particularly hard algo to code and if you bothered to put
it together in a reliable manner, it would be fast, safe and convenient
to use without offsetting the stack by an unpredictable amount.
Regards,
hutch at movsd dot com
.
- Follow-Ups:
- Re: Library Design, f0dder's nightmare.
- From: f0dder
- Re: Library Design, f0dder's nightmare.
- References:
- Library Design, f0dder's nightmare.
- From: hutch--
- Re: Library Design, f0dder's nightmare.
- From: japheth
- Re: Library Design, f0dder's nightmare.
- From: f0dder
- Library Design, f0dder's nightmare.
- Prev by Date: Re: Freudian slip at the old win32asm forum ?
- Next by Date: Re: Library Design, f0dder's nightmare.
- Previous by thread: Re: Library Design, f0dder's nightmare.
- Next by thread: Re: Library Design, f0dder's nightmare.
- Index(es):
Relevant Pages
|