Board index » cppbuilder » Allocating Bitmaps From Heap With New ?

Allocating Bitmaps From Heap With New ?

I'm using CPP Builder 4 Standard under Win98 SE, 128 meg RAM, my swap
file is the only file on a 2 gig partition.

I need to create large bitmaps.  The code below compiles and runs, no
problem.

   Graphics::TBitmap *bigbmp;
   bigbmp = new Graphics::TBitmap;
   bigbmp->Monochrome = true;
   bigbmp -> Width = 11000;
   bigbmp -> Height = 11000;
   < code to draw and print the image >
    delete bigbmp;

However, if I try to set the height and width to larger values, for
example....,

   bigbmp -> Width = 12000;
   bigbmp -> Height = 12000;

.... it compiles and runs, assigns the width OK but throws EOutOf
Resources when it tries to assign the height.

Builder's Help says EOutOf Resources indicates Windows has run out of
handles.  I use only one other handle (for the printer) and since it
runs fine for an 11000 X 11000 pixel bitmap, I think the problem is
that it's running out of heap memory.  Since my swap file is the only
file on a 2 gig partition and since I let Windows manage the swap
file, I don't think it's a swap file limitation.

I've read the Help on the new operator and related topics and it
appears that it is possible to allocate specific amounts of memory
from the heap to bitmaps via new.  But I can't get the syntax right.
Could someone please help me with the syntax ?    Thanks.

Kim

----------=<>{ Spam Shield ON }<>=-----------
Email to "thejunk...@telusplanet.net" gets
autotrashed....I never see it. Try **bergk-
at-telus**planet dot nut if you must email
------------------------------------------------

 

Re:Allocating Bitmaps From Heap With New ?


Quote
>    bigbmp -> Width = 12000;
>    bigbmp -> Height = 12000;
> .... it compiles and runs, assigns the width OK but throws EOutOf
> Resources when it tries to assign the height.

At 600Mb that's a mighty big bitmap! My suspicion is that the call to
CreateDIBSection or CreateBitmap or whatever it uses is failing. Testing
this should be your first port of call. See if it's possible to
CreateDIBSection something that big.

If it's not, see if it's possible to allocate the memory yourself first, and
then CreateDIBSection but letting it simply use your own memory, instead of
allocating the memory itself as it normally does. (I'm fairly sure that's
possible).

If that works okay, and if no one else offers you more helpful advice, I'd
be inclined to read through the source to graphics.pas to see exactly how
and when TBitmap creates its bitmap, and if you can make the change above.

In any case, I'd be wary of trusting Windows to manage a bitmap that big.
Commercial drawing programs like CorelDraw and Paintshop appear to store the
raw bits for the bitmap in their own format, so they can have better control
over when and how various pieces of it get paged to disk.

--
Lucian

Re:Allocating Bitmaps From Heap With New ?


On Mon, 11 Dec 2000 15:20:01 -0700, "Kim Bergman"

Quote
<thejunk...@telusplanet.net> wrote:

>I'm using CPP Builder 4 Standard under Win98 SE, 128 meg RAM, my swap
>file is the only file on a 2 gig partition.
 ... snip ...

Hi
Timage type bitmaps are limited to approx 16MB.
 It is possible to use larger bitmaps by using the OnPaint event and
using "SetDIBitsToDevice()" (or stretch) to copy the bitmaps to the
screen in the same way we used to do under W3.x. - (you will also need
to trap the pallette realisation messages).
  A bonus in doing this is it a lot quicker than letting TImage paint
it - but you have to do a lot of the work yourself, managing client
area rect's etc.

 If the above does not make sense try finding out how to paint under
w3.x - or be more specific and I will try and help

andy

Re:Allocating Bitmaps From Heap With New ?


On Mon, 11 Dec 2000 23:09:56 GMT, a.a.prot...@NOSPAMcare4free.net

Quote
(andy) wrote:
>On Mon, 11 Dec 2000 15:20:01 -0700, "Kim Bergman"
><thejunk...@telusplanet.net> wrote:

>>I'm using CPP Builder 4 Standard under Win98 SE, 128 meg RAM, my swap
>>file is the only file on a 2 gig partition.
> ... snip ...

>Hi
>Timage type bitmaps are limited to approx 16MB.
... smip ...
>w3.x - or be more specific and I will try and help

>andy

 PS - depending on your needs you may do better holding the big
bitmaps in (real) memory and copy the required scanlines to
Timage->Bitmap's scanlines ?

 andy

Re:Allocating Bitmaps From Heap With New ?


Quote
"Lucian Wischik" <ljw1...@cam.ac.uk> wrote in message

news:913ko6$96i7@bornews.inprise.com...
Quote
> >    bigbmp -> Width = 12000;
> >    bigbmp -> Height = 12000;
> > .... it compiles and runs, assigns the width OK but throws EOutOf
> > Resources when it tries to assign the height.

> At 600Mb that's a mighty big bitmap!

600 MB?  You were thinking of a color bitmap?  This is just
monochrome.

12000 ^2 pixels  /  (1 bit per pixel  * 8 bits per byte * 1024^2 bytes
per meg ) = 17 MB approx.

And I just used my code to create a 13,750 X 9700 pixel monochrome
bitmap and save it to disk.  Windows reports 16.2 MB for the file size
which is almost exactly what I get using my method of calculating.

Maybe I'm counting pixels and bytes incorrectly so I need to clear
that up first.  Then tell me if I should investigate CreateDIBSection
or whatever.

Quote
> My suspicion is that the call to
> CreateDIBSection or CreateBitmap or whatever it uses is failing.
Testing
> this should be your first port of call. See if it's possible to
> CreateDIBSection something that big.

> If it's not, see if it's possible to allocate the memory yourself
first, and
> then CreateDIBSection but letting it simply use your own memory,
instead of
> allocating the memory itself as it normally does. (I'm fairly sure
that's
> possible).

> If that works okay, and if no one else offers you more helpful
advice, I'd
> be inclined to read through the source to graphics.pas to see
exactly how
> and when TBitmap creates its bitmap, and if you can make the change
above.

> In any case, I'd be wary of trusting Windows to manage a bitmap that
big.
> Commercial drawing programs like CorelDraw and Paintshop appear to
store the
> raw bits for the bitmap in their own format, so they can have better
control
> over when and how various pieces of it get paged to disk.

> --
> Lucian

Re:Allocating Bitmaps From Heap With New ?


Quote
"Kim Bergman" <thejunk...@telusplanet.net> wrote in message

news:3a3591c6_1@dnews...

Quote

> "Lucian Wischik" <ljw1...@cam.ac.uk> wrote in message
> news:913ko6$96i7@bornews.inprise.com...
> > >    bigbmp -> Width = 12000;
> > >    bigbmp -> Height = 12000;
> > > .... it compiles and runs, assigns the width OK but throws
EOutOf
> > > Resources when it tries to assign the height.

> > At 600Mb that's a mighty big bitmap!

> 600 MB?  You were thinking of a color bitmap?  This is just
> monochrome.

> 12000 ^2 pixels  /  (1 bit per pixel  * 8 bits per byte * 1024^2
bytes
> per meg ) = 17 MB approx.

> And I just used my code to create a 13,750 X 9700 pixel monochrome
> bitmap and save it to disk.  Windows reports 16.2 MB for the file
size
> which is almost exactly what I get using my method of calculating.

> Maybe I'm counting pixels and bytes incorrectly so I need to clear
> that up first.  Then tell me if I should investigate
CreateDIBSection
> or whatever.

> > My suspicion is that the call to
> > CreateDIBSection or CreateBitmap or whatever it uses is failing.
> Testing
> > this should be your first port of call. See if it's possible to
> > CreateDIBSection something that big.

OK, thanks to links posted in other threads in this group, I was able
to find the answer.  It's at
http://support.microsoft.com/support/kb/articles/Q227/6/17.ASP

It appears creating bitmaps of the size I need to work with is doomed
from the start under Win 95/98 due to limits inherent in the
kernel....the GDI routines are 16 bit!  And Bill has the gall to
advertise it as a 32 bit OS!!!    An application may be able to create
1 or 2 "big" bitmaps but its unpredictable and prone to errors that
can be fixed only with a reboot.  According to the article above, Win
ME's kernel is better at handling large bitmaps, or is that just
another of Bill's many lies?

I guess on Win 95/98 the only way to work with monster size bitmaps is
to chop it up into several smaller ones and hope for the best.

Quote
> > In any case, I'd be wary of trusting Windows to manage a bitmap
that
> big.

I've never trusted Windows to do *anything* correctly.

Thanks for the reply Lucian, you did help get me on the right track by
mentioning CreateDIBSection. And thanks to those who posted helpful
links in response to Nick Ford's question regarding "Problem Drawing
to Printer Canvas".

    Kim

Re:Allocating Bitmaps From Heap With New ?


Somewhere I finally found (and then misplaced) the help article
explaining that bitmap sizes are restricted on win9x.

I have encountered this probelm, and found it's very unpredictable, to
boot.
I would suggest an alternative approach - some kind of virtual view for
efficiency.

HTH

Quote
Kim Bergman wrote:
> I'm using CPP Builder 4 Standard under Win98 SE, 128 meg RAM, my swap
> file is the only file on a 2 gig partition.

> I need to create large bitmaps.  The code below compiles and runs, no
> problem.

>    Graphics::TBitmap *bigbmp;
>    bigbmp = new Graphics::TBitmap;
>    bigbmp->Monochrome = true;
>    bigbmp -> Width = 11000;
>    bigbmp -> Height = 11000;
>    < code to draw and print the image >
>     delete bigbmp;

> However, if I try to set the height and width to larger values, for
> example....,

>    bigbmp -> Width = 12000;
>    bigbmp -> Height = 12000;

> .... it compiles and runs, assigns the width OK but throws EOutOf
> Resources when it tries to assign the height.

> Builder's Help says EOutOf Resources indicates Windows has run out of
> handles.  I use only one other handle (for the printer) and since it
> runs fine for an 11000 X 11000 pixel bitmap, I think the problem is
> that it's running out of heap memory.  Since my swap file is the only
> file on a 2 gig partition and since I let Windows manage the swap
> file, I don't think it's a swap file limitation.

> I've read the Help on the new operator and related topics and it
> appears that it is possible to allocate specific amounts of memory
> from the heap to bitmaps via new.  But I can't get the syntax right.
> Could someone please help me with the syntax ?    Thanks.

> Kim

> ----------=<>{ Spam Shield ON }<>=-----------
> Email to "thejunk...@telusplanet.net" gets
> autotrashed....I never see it. Try **bergk-
> at-telus**planet dot nut if you must email
> ------------------------------------------------

  patrickmmartin.vcf
< 1K Download

Re:Allocating Bitmaps From Heap With New ?


Quote
"Patrick Martin" <patrickmmar...@freenet.co.uk> wrote in message

news:3A3F3FE4.7C4E5FC6@freenet.co.uk...

Quote
> Somewhere I finally found (and then misplaced) the help article
> explaining that bitmap sizes are restricted on win9x.

Maybe you're thinking of an article I just found on Microsoft
knowledge base, Article Q227617?
It pretty well sums up the problem, the 16 bit routines in the win9x
GDI and fragmentation of the kernel local descriptor table.

Quote

> I have encountered this probelm, and found it's very unpredictable,
to
> boot.

Unpredictable and insurmountable.  So I've learned to make the most of
it ... for now.  The graphics labs at www.efg2.com have been helpful,
thanks Earl F Glynn for an excellent site.  With examples and info
from the labs,  I've tripled the size of bitmap I can make on my
system from about 11,000 pixels square to over 35,000 square.  That's
good enough for a demo/beta version.

Quote
> I would suggest an alternative approach - some kind of virtual view
for
> efficiency.

Yes.  Creating images that size in memory is convenient but
inefficient.  I'll be making some changes but I need to learn a little
more about basic graphic techniques.  I don't think I've fully
digested all I've read in the past 5 days.  No doubt I'll have a few
more questions :)  Hope to hear from you again.

_____________

Kim

Quote
> HTH

> Kim Bergman wrote:

> > I'm using CPP Builder 4 Standard under Win98 SE, 128 meg RAM, my
swap
> > file is the only file on a 2 gig partition.

> > I need to create large bitmaps.  The code below compiles and runs,
no
> > problem.

> >    Graphics::TBitmap *bigbmp;
> >    bigbmp = new Graphics::TBitmap;
> >    bigbmp->Monochrome = true;
> >    bigbmp -> Width = 11000;
> >    bigbmp -> Height = 11000;
> >    < code to draw and print the image >
> >     delete bigbmp;

> > However, if I try to set the height and width to larger values,
for
> > example....,

> >    bigbmp -> Width = 12000;
> >    bigbmp -> Height = 12000;

> > .... it compiles and runs, assigns the width OK but throws EOutOf
> > Resources when it tries to assign the height.

> > Builder's Help says EOutOf Resources indicates Windows has run out
of
> > handles.  I use only one other handle (for the printer) and since
it
> > runs fine for an 11000 X 11000 pixel bitmap, I think the problem
is
> > that it's running out of heap memory.  Since my swap file is the
only
> > file on a 2 gig partition and since I let Windows manage the swap
> > file, I don't think it's a swap file limitation.

> > I've read the Help on the new operator and related topics and it
> > appears that it is possible to allocate specific amounts of memory
> > from the heap to bitmaps via new.  But I can't get the syntax
right.
> > Could someone please help me with the syntax ?    Thanks.

> > Kim

> > ----------=<>{ Spam Shield ON }<>=-----------
> > Email to "thejunk...@telusplanet.net" gets
> > autotrashed....I never see it. Try **bergk-
> > at-telus**planet dot nut if you must email
> > ------------------------------------------------

Other Threads