Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about memory allocation

Status
Not open for further replies.

rsshetty

Programmer
Dec 16, 2003
236
0
0
US
I have a small problem with memory allocation.

typedef struct
{
int a;
int *b;
}Node;

class B
{
int label;
Node n[10];
}

....

void B::somefunction(int user)
{
.....
n.b = (int *)malloc(sizeof(int)*nuser)
.....
}
I want be able to dynamically declare Node n[10]. What I mean it that I will not know in advance if n[10] is enough or if I require more. I tried a couple of ways of allocating memory with no success.
Any help will be appreciated.



rsshetty.
It's always in the details.
 
What about using a STL container?
With a vector object for example :

Code:
#include <vector>
using std::vector;

class B
{
private:
  int label;
  vector<Node> nodes;
};

--
Globos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top