|
-
Mar 20th, 2002, 05:17 PM
#1
Thread Starter
Frenzied Member
Dynamic Allocation ??
I dunno if thats what its called but, heres what i need to do, when i try it i keep getting erros to do with memory and stuff not working properly.
I have a class:
Code:
class Connection {
public:
int socket;
};
I then need to have an array of this which can be set at run time, ie i can have 10 connections or 2. this is what i tried;
Code:
int amount = 10;
Connection *conn;
delete [] conn;
conn = new Connection[amount];
Should that work ? or is it all wrong ?
-
Mar 20th, 2002, 06:01 PM
#2
Fanatic Member
Read up on this part of a chapter from Sams TYSC++ in 21 Days... http://newdata.box.sk/bx/c/htm/ch11.htm#Heading18
Digital-X-Treme
Contact me on MSN Messenger: [email protected]
[VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
/ (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]
-
Mar 20th, 2002, 07:05 PM
#3
Fanatic Member
Almost right.
Code:
int amount;
Connection* conn;
cout << "Enter amount: ";
cin >> amount;
conn = new Connection[amount];
//...
delete [] conn; // VERY IMPORTANT - do not leave out or else you will have a memory leak.
Alcohol & calculus don't mix.
Never drink & derive.
-
Mar 20th, 2002, 10:29 PM
#4
I would suggest that you use vectors, but I know that this is going to be exported from a DLL, and its a pain in the arse to do that =).
I would go with the linked list approach, especially since it would be handy to add and remove sockets from the list. I suggest reading up on linked lists.
Z.
-
Mar 21st, 2002, 03:07 AM
#5
Thread Starter
Frenzied Member
Thanks guys.
Zaei in this case its ok for this to be a static array, its not the actual socket data just the available slots for useres to connect on.
-
Mar 21st, 2002, 08:58 AM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|