473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

bitmap array

Hi

I create bitmap array :

Graphics::TBitmap ***bitmap;

bitmap = new Graphics::TBitmap**[x];
for (int s=0;s<x;s++)
{
bitmap[s] = new Graphics::TBitmap*[y];
for (int u=0;u<y;u++)
bitmap[s][u] = new Graphics::TBitmap;
}

How can i delete this array ?

for (int s=0;s<x;s++)
{
for (int u=0;u<y;u++)
delete bitmap[s][u];
delete bitmap[s];
}

or I have to use "delete[]" command?

regards

Sebastor


Jan 27 '06 #1
3 4825
Sebastor wrote:
I create bitmap array :

Graphics::TBitmap ***bitmap;

bitmap = new Graphics::TBitmap**[x];
for (int s=0;s<x;s++)
{
bitmap[s] = new Graphics::TBitmap*[y];
for (int u=0;u<y;u++)
bitmap[s][u] = new Graphics::TBitmap;
Since individual element is created using "regular" 'new'...
}

How can i delete this array ?

for (int s=0;s<x;s++)
{
for (int u=0;u<y;u++)
delete bitmap[s][u];
You should use "regular" 'delete'
delete bitmap[s];
But since 'bitmap[s]' was created using 'new[]', you must use 'delete[]':

delete[] bitmap[s];
}
And you forgot to delete the 'bitmap' itself here...

or I have to use "delete[]" command?


Depends. See above.

V
Jan 27 '06 #2
On Fri, 27 Jan 2006 22:58:57 +0100, "Sebastor" <br********@onet.pl>
wrote:
Hi

I create bitmap array :

Graphics::TBitmap ***bitmap;

bitmap = new Graphics::TBitmap**[x];
for (int s=0;s<x;s++)
{
bitmap[s] = new Graphics::TBitmap*[y];
for (int u=0;u<y;u++)
bitmap[s][u] = new Graphics::TBitmap;
}

How can i delete this array ?

for (int s=0;s<x;s++)
{
for (int u=0;u<y;u++)
delete bitmap[s][u];
delete bitmap[s];
}

or I have to use "delete[]" command?

regards

Sebastor


The rule is, use delete[] wherever you used new[]. You used new[]
sometimes, and new at other times. Don't become confused by the array
subscripts, which have nothing to do with delete[].

--
Bob Hairgrove
No**********@Home.com
Jan 27 '06 #3
In article <dr**********@opal.icpnet.pl>,
"Sebastor" <br********@onet.pl> wrote:
Hi

I create bitmap array :

Graphics::TBitmap ***bitmap;

bitmap = new Graphics::TBitmap**[x];
for (int s=0;s<x;s++)
{
bitmap[s] = new Graphics::TBitmap*[y];
for (int u=0;u<y;u++)
bitmap[s][u] = new Graphics::TBitmap;
}

How can i delete this array ?

for (int s=0;s<x;s++)
{
for (int u=0;u<y;u++)
delete bitmap[s][u];
delete bitmap[s];
}

or I have to use "delete[]" command?


This is a great example why you should use the standard containers...

template < typename T >
class Array {
int _x;
std::deque< T > _array;
public:
Array( int x, int y ): _x( x ), _array( x * y ) { }
const T& operator()( int x, int y ) const {
return _array[ x * _x + y ];
}
T& operator()( int x, int y ) {
return _array[ x * _x + y ];
}
};

Now create your array:

Array< Graphics::TBitmap > bitmap( x, y );

You get proper destruction as well as copy semantics for free.
Jan 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
1
by: Sharon | last post by:
I have 2 questions that are just the opposite to one another: (1) I need to read an image file (like bitmap, jpeg etc.) and to save only its data, I need to save his data in a raw data format,...
6
by: Crirus | last post by:
Strange behaviour: I havea bitmap that I draw and add to an array of bitmaps... Do I have to create a bitmap using New every time? I tried to draw the bitmap in a for loop alike this: Dim...
5
by: Lance | last post by:
I need to create a Drawing.Bitmap from an array of integer values. My current technique creates a bitmap that eventually becomes corrupt (i.e., the bitmap's pixels change to a different color...
10
by: pcnerd | last post by:
I'm a VB.NET newbie. I've created a program that plots pixels at random on the form. I have a 19" LCD monitor with a resolution set to 1280 by 1024. If you do the math, that means that there are...
3
by: Iwanow | last post by:
Hello! My goal is to develop a program that opens a bitmap, copies its pixels to an ArrayList in order to perform some complex calculations (edge detection, Hough transform etc.), and save...
2
by: =?Utf-8?B?UHJ6ZW1v?= | last post by:
Hi, I would like to have a web service method sending a bitmap image. But code like do not work: <WebMethod()_ Public Function GetBitmap() As Drawing.Bitmap Dim a As New...
5
by: stef | last post by:
hello I can find all kind of procedures to convert an array to a bitmap (wxPython, PIL), but I can't find the reverse, either - convert a bitmap to an array or - read a bitmap file to an...
20
by: Joe Duchtel | last post by:
Hello - I have the following code to get a bitmap from the clipboard and to save it to a *.png file ... Dim lData As IDataObject = Clipboard.GetDataObject() If...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.