473,397 Members | 1,960 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,397 software developers and data experts.

dynamic array with pointer

Hi,
I want to create a dynamic array with pointer, without allocation of the
memory.
I tried it so:

objekt **ob= new objekt[size];

It is not working, because he will parameter for the Konstructor ob objekt.
It works in the following way

objekt **ob= (object**) new DWORD[size];

but I get _CrtCheckMemory errors, althought all datas in the array work all
right.
Can anybody help me please, Thank you
Nils
Jul 22 '05 #1
5 10626
Nils wrote in news:bp**********@ariadne.rz.tu-clausthal.de:
Hi,
I want to create a dynamic array with pointer, without allocation of
the memory.
I tried it so:

objekt **ob= new objekt[size];
objekt *ob= new objekt[size];

Later do:

delete [] ob;

It is not working, because he will parameter for the Konstructor ob
objekt. It works in the following way

objekt **ob= (object**) new DWORD[size];

but I get _CrtCheckMemory errors, althought all datas in the array
work all right.


If you need more help then you should say what you are trying to do.
Its not clear why you are writing objekt **ob above, is this a 2D
array or it objekt a base class and you want an array of derived
objects.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2
Nils wrote:
Hi,
I want to create a dynamic array with pointer, without allocation of the
memory.
I tried it so:

objekt **ob= new objekt[size];

It is not working, because he will parameter for the Konstructor ob objekt.
It works in the following way

objekt **ob= (object**) new DWORD[size];

but I get _CrtCheckMemory errors, althought all datas in the array work all
right.
Can anybody help me please, Thank you


I think what you are tring to say is that you want a dynamic
array capable of handling 'size' objects, but you don't want
all that memory allocated immediately, nor the objekt ctor
being called. Probably your best bet would be to use
std::vector< wrapped_ptr<objekt> >. Where wrapped_ptr is
your favourite smart pointer implementation.

Jul 22 '05 #3
Hi,

I use ** because I alreade have so Objects, so I don't want to have new
memory allocated. I need the array as a kind of a "hashtable" for the
pointers to the Object. I think I found a way to do it:

Objekt **ob=new ob*[size];

But thought an array should be faster, if I know the position where the
information is, isn't it?

Thanks for your Help!!

"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> schrieb im Newsbeitrag
news:Xn**********************************@195.129. 110.201...
Nils wrote in news:bp**********@ariadne.rz.tu-clausthal.de:
Hi,
I want to create a dynamic array with pointer, without allocation of
the memory.
I tried it so:

objekt **ob= new objekt[size];


objekt *ob= new objekt[size];

Later do:

delete [] ob;

It is not working, because he will parameter for the Konstructor ob
objekt. It works in the following way

objekt **ob= (object**) new DWORD[size];

but I get _CrtCheckMemory errors, althought all datas in the array
work all right.


If you need more help then you should say what you are trying to do.
Its not clear why you are writing objekt **ob above, is this a 2D
array or it objekt a base class and you want an array of derived
objects.

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Jul 22 '05 #4
Nils wrote in news:bp**********@ariadne.rz.tu-clausthal.de:
Hi,
[top rearranged]
"Rob Williscroft" <rt*@freenet.REMOVE.co.uk> schrieb im Newsbeitrag
news:Xn**********************************@195.129. 110.201...
Nils wrote in news:bp**********@ariadne.rz.tu-clausthal.de:
> Hi,
> I want to create a dynamic array with pointer, without allocation of
> the memory.
> I tried it so:
>
> objekt **ob= new objekt[size];
objekt *ob= new objekt[size];

Later do:

delete [] ob;
>
> It is not working, because he will parameter for the Konstructor ob
> objekt. It works in the following way
>
> objekt **ob= (object**) new DWORD[size];
>
> but I get _CrtCheckMemory errors, althought all datas in the array
> work all right.


If you need more help then you should say what you are trying to do.
Its not clear why you are writing objekt **ob above, is this a 2D
array or it objekt a base class and you want an array of derived
objects.

I use ** because I alreade have so Objects, so I don't want to have new
memory allocated. I need the array as a kind of a "hashtable" for the
pointers to the Object. I think I found a way to do it:

Objekt **ob=new ob*[size];

I think you mean

Objekt **ob=new Objekt *[size];

If you already have the pointers then this is correct, but please
consider,

#include <vector>

std::vector< Objekt * > ob;

in a function use:

ob.resize( size );

for ( unsigned position = 0; position < size; ++position )
{
ob[ position ] = Objekt_pointer_for_position;
}

std::vector will manage the memory for you no need to call delete []
later.
But thought an array should be faster, if I know the position where the
information is, isn't it?


Not sure what you mean here, but an array or std::vector will let you
find a pointer from its index (position) in a single operation.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #5
Nils wrote:
Hi,

I use ** because I alreade have so Objects, so I don't want to have
new memory allocated. I need the array as a kind of a "hashtable"
for the pointers to the Object. I think I found a way to do it:

Objekt **ob=new ob*[size];

But thought an array should be faster, if I know the position where
the information is, isn't it?


That depends on what you want to do and how the data itself is arranged.
I mean, if you want an array of pointers that point to the objects, you
already must have some type of container that contains those objects
themselves.

Jul 22 '05 #6

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

Similar topics

4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
14
by: Steven Taylor | last post by:
I'm learning C++ from C++ Primer Plus 5th edition. I'm struggling at the moment with declaring an array of three structures by using 'new' to allocate memory. (this is one of the programming...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
12
by: googlinggoogler | last post by:
Hi, Im new to C++ and trying to self teach myself whilst I sit at my unentertaining day job (thought i'd put that across before im accused of cheating on my homework, im 45...) Anyway I'm...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
0
by: pjr | last post by:
Using VS2005, I dynamically create an event delegate. Code follows question. My method gets the event's parameters and passes them onto a common event handler. My delegate gets called when expected...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
20
by: sirsnorklingtayo | last post by:
hi guys please help about Linked List, I'm having trouble freeing the allocated memory of a single linked list node with a dynamic char* fields, it doesn't freed up if I use the FREE()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.