🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #17678

Re: Screen

#17678
From: Early Ehlinger
Date: Wed, 05 Mar 2003 16:27
44 lines
4133 bytes
"Mockvichev Nikolai" <mnv@papillon.ru> wrote:
> Yes, we know this, and more, TMemoryStream has inherited property called
> Size: "Use Size to find the size of the stream. Size is used internally
> in routines that read and write to and from the stream. Setting the Size
> property of TStream does nothing. Some descendants of TStream override
> this property to allow applications to change the size of the resource
> accessed using the stream. "
>   "does nothing" is very strange for class named TMemoryStream, in my
> opinion :-)

Oh, contraire!

TMemoryStream is one of those descendents that actually does change the size
of the resource (allocated memory).  Setting the Size property ***does***
have an effect with TMemoryStream; it allocates the specified number of
bytes.

However, this isn't the effect we want in this particular case, because you
cannot reliably predict the number of bytes required to hold the JPEG.  If
you choose too high, then the TMemoryStream will contain too many bytes and
have a bunch of garbage after the actual JPEG data.  If you choose too low,
then the MemoryStream will not have enough capacity and will end up
reallocating during the JPEG write.  This is why I suggested (and
implemented) TMemoryStreamWithCapacity - you have the option of being very
aggressive in your preallocation, because although the capacity will be
high, the Size of the TMemoryStream will be correct after the JPEG is saved
into it.  In other words, you are more likely to get through the JPEG save
without any reallocation *and* it gives the desired results.

You mentioned memcpy in your previous post; that isn't a reasonable option
in this case, because the original poster was trying to use the
TMemoryStream as an intermediate storage location for a JPEG.  The JPEG code
in the VCL only knows how to write to TStream* (and by virtue of that, to
TMemoryStream, TFileStream, etc.).  There is no clean opportunity to use
memcpy in this situation.  Therefore, we are stuck trying to optimize the
TStream* approach.

--
-- Early Ehlinger CEO, ResPower Inc - Toll-Free : 866-737-7697 --
- RenderFarm - Lightwave , 3dSMax , Bryce , Maya , AfterEffects -
--- www.respower.com -- 500+ GHz Starting At USD$0.50/GHz*Hour --
----------------- SuperComputing For the Masses! ----------------
"I'm so busy programming my computer to let me be lazy, I never
get any rest!" - John Kaster
Technical Details
Message-ID: <3e661209@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3e54df1e$1@newsgroups.borland.com> <3e54e70b@newsgroups.borland.com> <3e54ef6e@newsgroups.borland.com> <3e54f156@newsgroups.borland.com> <3e54fa6f@newsgroups.borland.com> <3e550095$1@newsgroups.borland.com> <3e557074$1@newsgroups.borland.com> <MPG.18bfe0b08613f83a98970a@newsgroups.borland.com> <3e55e0f0@newsgroups.borland.com> <MPG.18c006adda2fd07998970d@newsgroups.borland.com> <3e55ee44$1@newsgroups.borland.com> <MPG.18c021c54fabdd0898970f@newsgroups.borland.com> <3e5971c3$1@newsgroups.borland.com> <3e5b844a$1@newsgroups.borland.com> <3e5b96cc@newsgroups.borland.com> <3e5fd2f1$1@newsgroups.borland.com> <3e62a8b2$1@newsgroups.borland.com> <3e62af4f@newsgroups.borland.com> <3e62b0fb@newsgroups.borland.com> <1046752275.599401@fionika.papillon.ru.N.O.S.P.A.M> <3e64bb8d@newsgroups.borland.com> <1046838017.105816@fionika.papillon.ru.N.O.S.P.A.M>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,9afd9565ba185f43
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-03-05 07:18:11 PST
From: "Early Ehlinger" <early@respower.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3e54df1e$1@newsgroups.borland.com> <3e54e70b@newsgroups.borland.com> <3e54ef6e@newsgroups.borland.com> <3e54f156@newsgroups.borland.com> <3e54fa6f@newsgroups.borland.com> <3e550095$1@newsgroups.borland.com> <3e557074$1@newsgroups.borland.com> <MPG.18bfe0b08613f83a98970a@newsgroups.borland.com> <3e55e0f0@newsgroups.borland.com> <MPG.18c006adda2fd07998970d@newsgroups.borland.com> <3e55ee44$1@newsgroups.borland.com> <MPG.18c021c54fabdd0898970f@newsgroups.borland.com> <3e5971c3$1@newsgroups.borland.com> <3e5b844a$1@newsgroups.borland.com> <3e5b96cc@newsgroups.borland.com> <3e5fd2f1$1@newsgroups.borland.com> <3e62a8b2$1@newsgroups.borland.com> <3e62af4f@newsgroups.borland.com> <3e62b0fb@newsgroups.borland.com> <1046752275.599401@fionika.papillon.ru.N.O.S.P.A.M> <3e64bb8d@newsgroups.borland.com> <1046838017.105816@fionika.papillon.ru.N.O.S.P.A.M>
Subject: Re: Screen
Date: Wed, 5 Mar 2003 10:27:07 -0600
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 206.166.224.226
Message-ID: <3e661209@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1046876681 206.166.224.226 (5 Mar 2003 07:04:41 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail