| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Auto string-length deter |
On 07 Oct 96, Frank Adam wrote to Paul Wankadia --
PW> What would I have to do? Use strdup() to duplicate the string locally
PW> and then sizeof() that duplicate string perhaps???
FA> Shivers. Alloc(), strcpy(),sizeof(), and free() just to find the byte
FA> length ? I'm not sure if it'll work anyway, i think it just copies
FA> strlen(string).
Yeah -- realised that later...
FA> Best way is to just send the old fashioned maxsize to the function,
Seems that's the only way. Or I could bid this echo farewell and move into
OOP completely (which I'd rather not do ATM) ...
FA> the string may not always be allocated just for the input anyway.
Eh? OH!
FA> Eg. What happens if..
[example deleted]
FA> Ok, then i would have to make sure in the calling function that the
FA> returned string is big enough to manipulate further.
Oh bother...
[second example deleted]
FA> Now i've saved a sizeof(mystr) to send, but lost a sizeof call and an
FA> if else statement on return, not to mention the extra work the
FA> getstr() function had to do.
Yeah -- too messy for my liking...
FA> I know what you're trying to do, i worked on the same thing few months
FA> back, that's exactly what made me do that function with heapwalk().
FA> It's good fun, but i haven't used that code since.
So you mean it CAN be done with heapwalk() (if the array was allocated from
the heap) ???
PW> BTW how can I make a pointer to point to a set place in memory (i.e.
PW> segment and offset) ???
FA> Take a look at MK_FP(), and also FP_OFF(),FP_SEG().
Will do.
[another example deleted]
FA> Btw MK_FP(), is not ISO, but there is a portable replacement in
FA> SNIPPETS. Or you can always swipe VidMgr's #define for it, it looks
FA> close.:-)
Where's the closest SNIPPETS site to 3:640/772.3 that I can pick the whole
bunch up from?
FA> Perhaps if the string is global it may also work, but i didn't try or
PW> What's wrong with global variables? :)
FA> Nothing when used in moderation, that was just a preemptive strike in
FA> case i was wrong..:)
I was taught to "hate" global variables... Come to think of it -- why ARE
they bad anyway?
FA> PS: if portability is not an issue look at heapwalk in Borland, or go
PW> What does heapwalk() do? (Forgive all these questions -- I only got
FA> Heapwalk goes through the internal allocation table, and report the
FA> number of bytes allocated to each variable and the state of the memory.
Clipped Borland's example and ran it... Seems rather interesting! Could
possibly be used for binary trees, recursive searches and the like (well, to
my young mind anyway :)
FA> With a bit of coding it can return the REAL size of any variable.
Then that's just what I'll have to do!
FA> I've posted a piece of code here few months back on that, but i can't
FA> seem to find it just now. Anyway it doesn't matter 'cause it was deemed
FA> to be highly non-portable.
Damn. What's ISO's address? I'll write to them and tell them to put this
heapwalk() function (and the rest of the heap-related functions of Borland's)
in the standard! :)
FA> WRT to the other mssg, an M3 is a BMW, a car that is :-)
Righto. So you want a BMW and I want a 10Mbit link to the US... :)
FA> L8r Frank (fadam{at}ozemail.com.au).
PPP? SLIP? Shell?
Chow.
Junyer Hakker.
--- PPoint 2.00
* Origin: Junyer's Workshop (3:640/772.3)SEEN-BY: 50/99 620/243 623/630 640/201 206 216 217 222 230 238 254 297 305 SEEN-BY: 640/309 370 375 386 531 535 547 739 750 772 773 820 821 822 823 890 SEEN-BY: 640/895 690/660 711/409 410 413 430 808 809 932 934 712/515 713/888 SEEN-BY: 714/906 800/1 @PATH: 640/772 531 201 820 711/409 808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.