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

Alternative to use array of objects

180 100+
Hello everybody,
In the following code, please suggest me to use alternative to array of objects.

Expand|Select|Wrap|Line Numbers
  1. //defined in x.h
  2. class interaction
  3. {
  4. public :
  5.                 int idnumber;         
  6.     int conditionnum;
  7.     int substructurenum;
  8.     int damage;          
  9.     int referencenum;    
  10.     int nextsamehashvalue;
  11.     int otherreactingss1; 
  12.     int otherreactingss2; 
  13.     int firstrelativerate;
  14.  
  15.  
  16. // constructor
  17. interaction() :
  18.       idnumber(0), conditionnum(0), substructurenum(0), damage(0),
  19.       referencenum(0), nextsamehashvalue(0),
  20.       otherreactingss1(0), otherreactingss2(0), firstrelativerate(0)
  21.      {}
  22. };
  23.  
  24. //defined in x.cpp
  25. interaction ia[11000]; //declared globally
  26.  
  27. void readinteraction() //declared globally
  28. {
  29.  for(int i=0; i<11000; ++i)
  30.  {
  31.    //here I will access each object of class 
  32.    //interaction via ia and put some value in
  33.    //each member variables defined in that class
  34.  }
  35. }
  36.  
  37. int main()
  38. {
  39.    readinteraction();
  40.    ofstream ialist(filename); //filename is a file where I will 
  41.                                        //write all the object(i.e ia contents)
  42.    ialist.write((char *) ia,sizeof(ia));  
  43.    ialist.close();
  44.    return 0;
  45. }
I dont want to use interaction ia[11000] in the above program
means I dont want to specify fixed object. I even dont want
interaction* ia[11000]

Is there any other solution?

Hi, Banfa!!!
I'm not able to solve my previous query.
I'm still looking any suggestion from you.

Thanks
Rajeev
Sep 7 '06 #1
1 6225
Banfa
9,065 Expert Mod 8TB
This really depends on what you are using the data for. If you are always going to have 11000 of these objects in use then there really is not harm in declaring the array statically. On the other hand if the number required is variable then you may be better of allocating them.

I wouldn't statically allocate an array of pointers though

interaction* ia[11000]; // <-- I would do this

Better to have a single pointer and allocate an array to it

interaction* ia;

ia = new interaction[11000];

but only if the 11000 is not constant.
Sep 7 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select...
3
by: McKirahan | last post by:
I said I wouldn't use "eval()" anymore but I need help to do it. Below is some stripped-down code (4 lines; watch for word-wrap) extracted from USGA.COM that preloads images: main_nav_home_F1...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
2
by: Tristan | last post by:
Hi, My code reads through a file of shapes adding each one to an ArrayList as it does so. The problem is that for files with large numbers of shapes, calling ArrayList.Add(MyShape) is...
9
by: John A Grandy | last post by:
In VB6 you could get away with the following code: Dim Index As Integer Dim ItemsCount As Integer Dim StringArray() As String Dim StringValue As String '....
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
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...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.