Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Memory Allocation for Structure / Class

Reply
Thread Tools

Memory Allocation for Structure / Class

 
 
akshay4friend@yahoo.com
Guest
Posts: n/a
 
      02-16-2005
Hi,
I am creating a structure / class having data type like

{
DOUBLE x;
DOUBLE y;
DOUBLE z;
}POINT3D;

now my data is stored in a file..so i need to create buffer to read
this points one by one...how i suppose to allocate memory for this
using NEW..i DONT want to create predefined fixed length array for this
as i dont know how many points are there in a file but i want to
allocate memory as i get next set of point. Can i use vector<> for such
type ? or is there any way to dynamically allocate memory to create
infinite or expandable array ? plz help
thanx in advance.

Akshay

 
Reply With Quote
 
 
 
 
SirMike
Guest
Posts: n/a
 
      02-16-2005
wrote:
> now my data is stored in a file..so i need to create buffer to read
> this points one by one...how i suppose to allocate memory for this
> using NEW..i DONT want to create predefined fixed length array for this
> as i dont know how many points are there in a file but i want to
> allocate memory as i get next set of point. Can i use vector<> for such
> type ? or is there any way to dynamically allocate memory to create
> infinite or expandable array ? plz help
> thanx in advance.

Use vector<>, IMHO the best way to do it. You can expand it, erase
elements, sort when you want - without much work.

--
the code is my strength
SirMike
 
Reply With Quote
 
 
 
 
Akshay
Guest
Posts: n/a
 
      02-16-2005
Hi,
Can anyone give me short example for this...I am using Vc++ 6.0.. how
to use vector to declare such type of array of structure / class ..
thanx
Akshay




SirMike <sirmike@****_SPAMMERSpoczta.onet.pl> wrote in message news:<cuv0h0$avr$>...
> wrote:
> > now my data is stored in a file..so i need to create buffer to read
> > this points one by one...how i suppose to allocate memory for this
> > using NEW..i DONT want to create predefined fixed length array for this
> > as i dont know how many points are there in a file but i want to
> > allocate memory as i get next set of point. Can i use vector<> for such
> > type ? or is there any way to dynamically allocate memory to create
> > infinite or expandable array ? plz help
> > thanx in advance.

> Use vector<>, IMHO the best way to do it. You can expand it, erase
> elements, sort when you want - without much work.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
memory allocation for structure array jvax C Programming 4 11-24-2010 11:43 PM
static memory allocation versus dynamic memory allocation Ken C Programming 24 11-30-2006 12:37 AM
Memory allocation in Structure to Structure pra_ramli@rediffmail.com C++ 2 03-09-2006 05:51 AM
What is the difference between dynamic memory allocation,and stack allocation ? chris C++ 6 10-28-2005 05:27 AM
Structure memory allocation Trying_Harder C Programming 4 09-16-2003 02:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57