472,958 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 6214
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.