|
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
|
|
|
|
|
Bevan C Bird wrote: how and when is the memory that is allocated by new, deleted?
Depends. Most modern operating systems will reclaim the memory when the process exits.
|
|
|
|
|
I may need to reuse the memory in this Table or possibly another one.
That is, while the process is running.
|
|
|
|
|
Bevan C Bird wrote: 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)?
somehow I missed that question from your first post... oops.
No it does not free the memory allocated when you used the new operator
Bevan C Bird wrote: I may need to reuse the memory in this Table or possibly another one.
I don't know what you mean by "reuse the memory". As long as you have the pointers in the vector you will have access to them. If you clear the vector, based on the code you posted, you will no longer have access to the memory.
|
|
|
|
|
Don't bother #include ing string.h and using char* : instead use #include <string> and
std::vector<std::string> and forget about memory allocation issues.
Steve
|
|
|
|
|
Is there any simple way how to change frame around the Edit box
(just color, but not for all edits, just for i want)
Or how to subclass Edit?
viliam
|
|
|
|
|
I can not access border in this message.
It draw rectangle around white part, but border are still there.
And when I turn off border in resource editor, my rect is partly covered by text background.
All Edit SubClass codeproject items, I had found, are about behaviour of Edit none of them about painting.
viliam
|
|
|
|
|
simple and it works fine
Thank you
viliam
|
|
|
|
|
search codeproject with keyword "SubClass" you will get many article, which will fulfill your need
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi
I'm new to Visual C++ and .NET Framework; I'm trying to display a bitmap image on a Windows Form in Visual Studio 2005 but am experiencing problems with this.
I have examples for VS 2003 but these don’t seem to work in VS 2005.
Does anyone have any examples of displaying a bitmap in VS 2005?
Any help appreciated
|
|
|
|
|
You asked on the C++ forum so on the c++ you can use of LoadImage for load image and use of WM_ERASEBKGND for show this image.;)
|
|
|
|
|
but he specified to use WinForms, so we can decently understand that he is on the wrong place...
|
|
|
|
|
Yeah I saw his question but I said to him you asked on the c++ forum its meaning if someone answer to him answer will be c++ or c++.net,right!?;)
|
|
|
|
|
Can anyone tell me where I can find an overview, directions, etc. on porting a Visual C++ 6.0 project to Visual Studio 2005?
Visual Studio 2005 says it will convert a Visual C++ Project, but I'm getting compilation errors with the original Visual C++ interface (the one defined in resource.h and the *.rc files), plus warnings like :
"WINVER not defined"
"too many actual parameters for macro 'ON_WM_ACTIVATE'
Should I try creating a new project with the old code?
Thanks.
|
|
|
|
|
Go to Google and in the Search box type: Microsoft Visual C++
Then click the "Search" button.
The first link in the list takes you to the "Visual C++ Developer Center" on MSDN, remember this for future reference (there might be like real information here useful to developers using Visual C++).
In the upper right hand corner of the page there is a box titled "Focus On", in the box the first link is titled "Migrating From Previous Versions of Visual C++"
good luck
|
|
|
|
|
|
Yeah thats right,but it was a prediction or you can solve mysterys!?
|
|
|
|
|
But where in google home page is the search box?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
I was able to address all of the problems and warnings I first mentioned, and the first application I tried to port is working.
However, I then tried to port another Visual C++ 6.0 project, and got a different set of errors.
This second application refers to some ACE include files for definitions shared by other applications.
This application is a GUI used to generate and edit ASCII files.
First, I get warnings of the form:
.../ace/OS.i(516):warning C4996'chdir' was declared depreciated
Then I get errors of the form:
.../ace/Task_T.i(15): error C2491:'ACE_Task<ace_synch_mutex_t,ace_synch_condition_t>::water_marks':definition of dllimport function not allowed.
Let me emphasize: this application refers to some ACE include files but does not include any ACE code. No ACE libraries are referenced in the project.
Any thoughts?
Thanks.
|
|
|
|
|
kmrbooks wrote: Any thoughts?
well there is this
kmrbooks wrote: .../ace/OS.i(516):warning C4996'chdir' was declared depreciated
and....
kmrbooks wrote: Let me emphasize: this application refers to some ACE include files but does not include any ACE code.
apparently that ace include file actually has code in it otherwise you would not get that compiler error. Also, IMHO changing the working directory is NOT "Best Practice".
I don't know what this 'ACE' library is but if the project doesn't use it, why does it include files from the library?
kmrbooks wrote: .../ace/Task_T.i(15): error C2491:'ACE_Task::water_marks':definition of dllimport function not allowed.
Did you look up that compiler error[^]?
|
|
|
|
|
Problem solved, our version of ACE was out of date.
Thanks for the prompt responses.
|
|
|
|
|
HELLO,
I HAVE A PROJECT IN C++ TO VALIDATE AN XML FILE LIKE:
file.xml:
<filtrecombine nom="seuillage rouge puis binaire" nbfiltres="2">
<descriptionglobale>
"Ce filtre produit un seuillage sur le rouge et transforme ensuite l'image en binaire"
<filtre nom="seuillageRVB" nbparam="6">
<description>
"filtre de seuillage selon les couleurs RVB"
<acces type="dll">
"./seuillageRVB.dll"
<param type_visuel="regle" nom="Rmin" min="0" max="255" valeur="10" type_donnee="short unsigned int" />
"rouge min"
<param type_visuel="regle" nom="Rmax" min="0" max="255" valeur="60" type_donnee="short unsigned int" />
"rouge max"
<param type_visuel="regle" nom="Vmin" min="0" max="255" valeur="0" type_donnee="short unsigned int" />
"vert min"
<param type_visuel="regle" nom="Vmax" min="0" max="255" valeur="0" type_donnee="short unsigned int" />
"vert max"
<param type_visuel="checkbox" nom="Bmin" min="0" max="255" valeur="0" type_donnee="short unsigned int" />
"bleu min"
<param type_visuel="regle" nom="Bmax" min="0" max="255" valeur="0" type_donnee="short unsigned int" />
"bleu max"
<filtre nom="binaire" nbparam="2">
<description>
"Ce filtre transforme une image en binaire: toutes les valeurs de couleur comprises dans la fenetre sont passees a 1, les autres a 0"
<acces type="dll">
"./binaire.dll"
<param type_visuel="regle" nom="Smin" min="0" max="255" valeur="0" type_donnee="short unsigned int" />
"Seuil mini"
<param type_visuel="regle" nom="Smax" min="0" max="255" valeur="60" type_donnee="short unsigned int" />
"Seuil maxi"
and his dtd file like:
]>
can you help me?
thanks
|
|
|
|
|
you posted some taged code which is understood as html by the web page.
please edit your message and check the little "Ignore HTML tags in this message (good for code snippets)" at the end of the typing textarea...
moreover, no need to type in caps lock, and please be more descriptive about what you already tried and where you're stuck.
also, for your validation part, do you know that it already exists some XML parsers which get an XML Document and a DTD file and which validates the XML input file ?
thanks.
|
|
|
|
|
Hi, I have a MDI project with multiple doc/views.
If I have multiple doc/views open how to I select
a paticular view and bring it to the foreground?
thx
|
|
|
|
|
With SetActive (...); or with SetWindowPos (specifying the Z-Order TOP)
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|