Dynamic Allocation

I am using to new operator to dynamically allocate memory for a multi-dimensional array ... What all other types of methods in dynamic allocation can I use besides the new operator ??? I am reading the data from a file which will store the content in the array and then use it later for computation ... The length of the array depends on the number of buses (power system) in the data file ... I was (with the new operator) reading the data file initially to find the number of buses and then using that number of memory allocation to the multi-dimensional array ...
Who is Participating?
nietodConnect With a Mentor Commented:
Use the STL vector<> class.  It is like an array but can resize ar run-time and it has features for inserting items within the array or removing them from the array.
>> What all other types of methods in
>> dynamic allocation can I use besides the
>> new operator
You can use malloc().  But why would you want to?

Is there any reason why you don't want to use new?

As a tottally different approach, you may wish to use a container class to store the data.  For example the STL vector<> class.

Note For 10 pts, you should be expecting a 1 or 2 word answer.  
You could use malloc or calloc . malloc is unitialized allocation and calloc is initialized. But new is the recommended mode of memory allocation in c++.
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

calloc is "initialized" only in the C, not C++, sense of initialized.  If the data to be allocated has a constructor, calloc does not call it.  new does.
arindam042099Author Commented:
Okay this is what I have to do:
I am writing this program for a power system which has say three transmission line and one transformer ...
frombus tobus impedance
1          2    .3
2          3    .4
3          4    .5
and the transformer data
5          3    .2

I want to allocate memory to a two dimensional array such that it becomes a 5*5 matrix ... when I do "new" I will have to read from the line data file and pick 4 and then search from the transformer data and pick 5 ... As you can see I want to avoid this searching method to size my array using the new operator ... and not only that I am talking about say 100 buses ...
I want the array to resize if I remove something out ... I DO NOT THINK I CAN DO THAT USING THE new operator ...
arindam042099Author Commented:

Can you provide me with an example

This is a 10 point question!  You got a more than 10 point answer to the original quesiton and a more than 10 point answer to a second question.  For 10 points you should ask a a question that deserves a Yes/No answer.  You should not be expecting source code.

In any case the STL is bejond the scope of ANY question.  It is well documented in many books, I recommend Bjarne Btroustrup's "The C++ programming Language"

vector< vector<double> > Matrix;

Matrix[0][0] = 1;
Matrix [0][1] = 2

arindam042099Author Commented:
Thanks for the help ... Sorry about the points ... When you mentioned STL earlier I had no clue what that was ...
Standard Template Library--STL.  A good C++ book will get you started.  Expect to spend a few hours learning it.  A lifetime mastering it.
All Courses

From novice to tech pro — start learning today.