Click here to Skip to main content
15,889,479 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to make server and client in one program? Pin
maglev_tgv12-Nov-07 15:30
maglev_tgv12-Nov-07 15:30 
AnswerRe: How to make server and client in one program? Pin
only coder12-Nov-07 16:23
only coder12-Nov-07 16:23 
GeneralRe: How to make server and client in one program? Pin
maglev_tgv12-Nov-07 17:55
maglev_tgv12-Nov-07 17:55 
QuestionHow to draw Moving Average in stock software efficiently? Pin
followait12-Nov-07 14:25
followait12-Nov-07 14:25 
QuestionSerial Port Communications Pin
sunny.rana12-Nov-07 11:37
sunny.rana12-Nov-07 11:37 
QuestionRe: Serial Port Communications Pin
David Crow12-Nov-07 16:56
David Crow12-Nov-07 16:56 
AnswerRe: Serial Port Communications Pin
QuickDeveloper12-Nov-07 19:51
QuickDeveloper12-Nov-07 19:51 
QuestionSimple memory deallocation question (C++) [modified] Pin
Bevan C Bird12-Nov-07 10:35
Bevan C Bird12-Nov-07 10:35 
I am building a dynamic data table type that can have its metadata defined at runtime,
so the Table class will have a vector containing charater arrays of unknown length when
the class is defined.
I need to make a decision about how to handle memory allocation/deallocation for the Table
class. In the trivial example below, how and when is the memory that is allocated by new, deleted?
If I clear() or erase() elements from the vector, will it also be the same as delete []'ing the contents of the vector (the arrays)?

#include <iostream>
#include <vector>
#include <string.h>

void Add_record(std::vector<char*> &Table){
char *n = new char[80];
strcpy(n, "Hello World!");
Table.push_back(n);
}

int main (void){
using namespace std;
vector<char*> Table;

for (int i = 0; i<10; ++i)
Add_record(Table);

for (int i = 0; i<10; ++i)
cout << "Table.at("<<i<<") = "<<Table.at(i)<<endl;

std::cin.get();
return 0;
}




-- modified at 16:43 Monday 12th November, 2007
AnswerRe: Simple memory deallocation question (C++) Pin
led mike12-Nov-07 10:48
led mike12-Nov-07 10:48 
GeneralRe: Simple memory deallocation question (C++) Pin
Bevan C Bird12-Nov-07 11:01
Bevan C Bird12-Nov-07 11:01 
GeneralRe: Simple memory deallocation question (C++) Pin
led mike12-Nov-07 11:25
led mike12-Nov-07 11:25 
AnswerRe: Simple memory deallocation question (C++) Pin
Stephen Hewitt12-Nov-07 12:28
Stephen Hewitt12-Nov-07 12:28 
QuestionEdit box Pin
viliam12-Nov-07 8:30
viliam12-Nov-07 8:30 
GeneralRe: Edit box Pin
viliam13-Nov-07 8:27
viliam13-Nov-07 8:27 
GeneralRe: Edit box Pin
viliam13-Nov-07 11:12
viliam13-Nov-07 11:12 
AnswerRe: Edit box Pin
ThatsAlok13-Nov-07 5:02
ThatsAlok13-Nov-07 5:02 
QuestionDisplaying a bitmap Pin
rover_boy12-Nov-07 5:55
rover_boy12-Nov-07 5:55 
AnswerRe: Displaying a bitmap Pin
Hamid_RT12-Nov-07 6:31
Hamid_RT12-Nov-07 6:31 
GeneralRe: Displaying a bitmap Pin
toxcct12-Nov-07 6:37
toxcct12-Nov-07 6:37 
GeneralRe: Displaying a bitmap Pin
Hamid_RT12-Nov-07 6:58
Hamid_RT12-Nov-07 6:58 
QuestionPort VC++ 6.0 project to Visual Studio 2005 Pin
kmrbooks12-Nov-07 3:40
kmrbooks12-Nov-07 3:40 
AnswerRe: Port VC++ 6.0 project to Visual Studio 2005 Pin
led mike12-Nov-07 4:42
led mike12-Nov-07 4:42 
JokeRe: Port VC++ 6.0 project to Visual Studio 2005 Pin
toxcct12-Nov-07 5:03
toxcct12-Nov-07 5:03 
GeneralRe: Port VC++ 6.0 project to Visual Studio 2005 Pin
Hamid_RT12-Nov-07 7:42
Hamid_RT12-Nov-07 7:42 
JokeRe: Port VC++ 6.0 project to Visual Studio 2005 Pin
Rajesh R Subramanian12-Nov-07 20:53
professionalRajesh R Subramanian12-Nov-07 20:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.