|
Cool, not surprised it eats RAM in debug - 80 bytes per tree node isn't that unreasonable.
As for release mode, have you considered looking at the source code for map to find out how big each node is? Presumably not as on one compiler I use each node contains three pointers, the data and the key. For a 32 bit machine that's 20 bytes and the allocator rounds everything up to the nearest multiple of 16 (so that 20 bytes becomes 32...) giving you ~ 320Mb.
So you're getting the correct magnitude, I wouldn't worry about it.
Ash
|
|
|
|
|
I agree, this is huge memory usage.Are you sure that the code is compiled into release mode.If you need to allocate such huge memory blocks why don't you consider dynamic allocation?This forum thread discusses how to estimate memory used by STL map.
Life is a stage and we are all actors!
|
|
|
|
|
Hi,
Are you checking the memory usage of a Debug build? Most compilers implement the debug memory allocator with extra padding around allocated memory.
Best Wishes,
-David Delaune
|
|
|
|
|
yu-jian wrote: ...it cose more than 800M memory.
How are you verifying this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi everybody. I'm tring to save image form webBrowser control. and i have the following code
mshtml::HTMLDocument^ document = dynamic_cast<mshtml::HTMLDocument^>(this->webBrowser1->Document->DomDocument);
mshtml::IHTMLElementCollection^ collImages = document->getElementsByTagName(L"img");
for (int i = 0; i < collImages->length; ++i)
{
mshtml::IHTMLImgElement^ img = safe_cast<mshtml::IHTMLImgElement^>(collImages->item(nullptr, i));
mshtml::IHTMLElementRender^ render = dynamic_cast<mshtml::IHTMLElementRender^>(img);
Bitmap^ bmp = gcnew Bitmap(img->width, img->height);
Graphics^ g = Graphics::FromImage(bmp);
IntPtr hdc = g->GetHdc();
<big>render->DrawToDC(hdc); </big>
g->ReleaseHdc(hdc);
delete g; g = nullptr;
bmp->Save(L"C:\\Test\\SaveImage.Jpg", System::Drawing::Imaging::ImageFormat::Jpeg);
}
I get the following error message
Error C2664: 'mshtml::IHTMLElementRender::DrawToDC' : cannot convert parameter 1 from 'System::IntPtr' to 'mshtml::_RemotableHandle %'
is there any one who knows how to fix this?
|
|
|
|
|
Wrong forum.You should post you question to C++/CLI forum.
Life is a stage and we are all actors!
|
|
|
|
|
I did. But no one seems to know.
|
|
|
|
|
voo doo12 wrote: I did. But no one seems to know.
OK.
I would advice you to write your own managed wrapper for of IHTMLElementRender interface, never mix managed and unmaged code, and avoid using C++/CLI for anything- it's not stable enough, it's very slow and inefficient, it's dirty.You are supposed to use C# or VB.NET, when you are targeting .NET platform. If you need to create something using C++ you should better use MFC libraries.Good luck.
Life is a stage and we are all actors!
|
|
|
|
|
Can you show me how I could save image(picture) from webbrowser control using MFC?
|
|
|
|
|
voo doo12 wrote: Can you show me how I could save image(picture) from webbrowser control using MFC?
Of course I can.
In MFC you should use Doc/View framework and CHtmlView class to access HTML using DOM.
[EDIT]I used Gdi+ to handle the images[/EDIT]
Here is my demo sample:
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0;
UINT size = 0;
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1;
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1;
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j;
}
}
free(pImageCodecInfo);
return -1;
}
void CWebBrowserAppView::OnFileSave()
{
LPDISPATCH pDisp=GetHtmlDocument();
IHTMLDocument2* pDoc;
HRESULT hr=0;
hr=pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc);
if(FAILED(hr))
{
pDisp->Release();
AfxMessageBox(L"Sorry dude, cast failed!");
return;
}
IHTMLElementCollection* pImgs;
hr=pDoc->get_images(&pImgs);
if(FAILED(hr))
{
pDoc->Release();
pDisp->Release();
AfxMessageBox(L"Sorry dude, can't get images list from document!");
return;
}
long length;
pImgs->get_length(&length);
IDispatch *pdImg;
IHTMLImgElement *pImg;
CLSID jpgClsid;
GetEncoderClsid(L"image/jpeg", &jpgClsid);
for(int i=0;i<length;i++)
{
_variant_t index = i;
hr = pImgs->item( index, index, &pdImg);
if(SUCCEEDED(hr))
{
hr= pdImg->QueryInterface( IID_IHTMLImgElement, (void **) &pImg);
if(SUCCEEDED(hr))
{
long width,height;
pImg->get_width(&width);
pImg->get_height(&height);
IHTMLElementRender* pRend;
hr=pImg->QueryInterface(IID_IHTMLElementRender,(void**)&pRend);
if(SUCCEEDED(hr))
{
Bitmap* pBmp=new Bitmap(width,height,PixelFormat24bppRGB);
Graphics* pGr=Graphics::FromImage(pBmp);
HDC gDc=pGr->GetHDC();
hr=pRend->DrawToDC(gDc);
pGr->ReleaseHDC(gDc);
if(SUCCEEDED(hr))
{
CString name;
name.Format(L"%d.jpg",i);
pBmp->Save(name,&jpgClsid,NULL);
name.ReleaseBuffer();
}
pRend->Release();
delete pBmp;
}
pImg->Release();
}
pdImg->Release();
}
}
pImgs->Release();
pDoc->Release();
pDisp->Release();
}
Life is a stage and we are all actors!
modified on Sunday, June 6, 2010 9:14 AM
|
|
|
|
|
Thanks very much. I'm not familiar with MFC but I will be. Thanks again
|
|
|
|
|
You are always wellcome.Study hard and you will get results.
Life is a stage and we are all actors!
|
|
|
|
|
Hi, I'm getting "0xC0000138: Ordinal Not Found" when deploying an executable that uses an ActiveX control on another machine. I have no idea where to start debugging this problem.
Basically, what happens is that the visual studio output window displays
"Loaded (correct)path_to_ocx file"
"First-chance exception at 0x7c964ed1 in project_name.exe: 0xC0000138: Ordinal Not Found."
"project_name.exe: Unloaded 'path_to_ocx'"
The problem is that this does not happen on the development machine
Any kick in the right direction would be a godsend. Thanks
|
|
|
|
|
eusto wrote: Hi, I'm getting "0xC0000138: Ordinal Not Found"
As you have probably figured out by now that error essentially means: "I found that DLL you need and I loaded it. But when I walked the export table I could not find one of the functions that you need."
eusto wrote: Any kick in the right direction would be a godsend. Thanks
I would recommend using Dependency Walker[^] on the target machine to track down the problem. You should open the OCX file and look for missing dependencies.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you for your answer, Dependency Walker is cool, i didn't know about it. Unfortunately, there doesn't seem to be any missing stuff on that ocx. I've contacted the vendor and asked them about it
Regards,
Eugen
|
|
|
|
|
Hi Eugen,
Did you try the Profiling option in the Dependency Walker system menu? This option should allow you to log everything... including calls to LoadLibrary and GetProcAddress. You should point it at the executable loading the OCX object.
Best Wishes,
-David Delaune
|
|
|
|
|
Ok, at this point i'm almost sure this is a vendor issue because recompiling my application on the target machine gets rid of the problem. I'm now betting on a weird licence implementation issue.
Thanks again for your help David.
Regards,
Eugen.
|
|
|
|
|
eusto wrote: Ok, at this point i'm almost sure this is a vendor issue because recompiling my application on the target machine gets rid of the problem.
You may be correct. However, what this would imply to me is that the vendor is dynamically linking with CRT/ATL. I would suggest testing on a third target computer and installing the Visual Studio redistributable package that matches your compiler version.
Microsoft Visual C++ 2008 Redistributable Package (x86)[^]
Microsoft Visual C++ 2005 Redistributable Package (x86)[^]
If your asking yourself why the vendor does not static link... its probably because there have been some recent severe ATL security vunerabilities. By dynamic linking... the vendor can rely on Microsoft updates to potentially fix the issue.
Active Template Library Security Update for Developers[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hello ,everyone !
Now I want to covert some strings, Just like this:
LPCSTR GetDate(int nTemp)
{
LPCSTR lpstr;
CString str = "";
str.Format("%d",nTemp);
...
}
Thanks for your reply !
|
|
|
|
|
See here[^], it's all in the documentation.
It's time for a new signature.
|
|
|
|
|
|
You're welcome. For future reference it's alway best to try the MSDN documentation first, then Google and/or the articles on CodeProject. Then if it's still not clear come here and ask the 7,000,000 or so experts for help.
It's time for a new signature.
|
|
|
|
|
|
Don't convert to a C style string until you really have to - you might be able to avoid fiddling around with new[] and delete[] and the good source of bugs that is. Usually you want a LPCSTR (ack, const char *) because you want to pass it to some legacy API that doesn't understand C++ style strings. If that's the case leave the conversion to just before you need the pointer to the characters you're after.
Cheers,
Ash
|
|
|
|
|
OK, this is basically algorithm related question and not the code.
Dunno if that is the correct section to post this but i'll try my luck
So, the thing i am trying to do is to parse | interpret JS - and i am pretty new to this.
I just need your advice if i am on a good way. Lets say we have 1 .js file with a function:
function concat_text(some_input_param){<br />
var value = "input text is: ";<br />
var output = value + some_input_param;<br />
return output;<br />
}
silly function. And its saved in a file silly.js
Next, in our index.html we have the following :
<script src="silly.js"></script><br />
<script><br />
var result = concat_text("some test text");<br />
document.write(result);<br />
</script>
Easy right? Ok, so what am i doing now? (all coding done with [C] btw)
1. getting first script source path (for ex. localhost/silly.js)
2. fetching this file (silly.js) content into predefined buffer for JS
3. next fetching second script source (between tags) and appending it to my JS buffer
4. define document.write function and pass the definition into JS interpreter
(in this case as all i need is to get output i can easily even skip that part
and just return the result into interpreter output buffer)
5. pass JS buffer into JS interpreter (i am working with google's V8)
6. .. and just get the result
Is it the right way? Or maybe there are different and more sufficient ways of doing it?
Like, there is no problem when we have a JS script on just one page and there no references
to another JS file, but i am thinking - how about for example, if there is ref to JQuery?
Fetching all its content - scary thing - it so big I am just pretty new to all this JS parsing stuff
and need someones advice.
Thanks in advance.
<div class="signature">011011010110000101100011011010000110100101101110
0110010101110011</div>
|
|
|
|