|
Thank you very much Mark,
CImage solved my problem (using load() on the filename, then GetWidth()).
Do you think using this (only about 10 times during the init stage of my application)
can create any significant overhead ?
However, I wasn't able to find how to retrieve that info from D3DXCreateTextureFromFile, which is what I actually use to load the image resource (to draw textures using sprites in DirectX).
|
|
|
|
|
Hanan888 wrote: Do you think using this (only about 10 times during the init stage of my application)
can create any significant overhead ?
It's less efficient than just parsing the file for the info since the
entire image is loaded into memory. If you're going to use the
loaded image anyway then it doesn't matter - loading once at the beginning is
way better than reloading every time you need them.
Hanan888 wrote: I wasn't able to find how to retrieve that info from D3DXCreateTextureFromFile
I believe IDirect3DTexture9::GetLevelDesc() should give you this info.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
IDirect3DTexture9::GetLevelDesc() gives you description of the levels of the texture. I haven't dive into it - but know that the picture get auto-scaled to a power of 2 dimension, for example:
(60 X 36) --> (64X64)
GetLevelDesc() helps ya get the 64x64 info.
I finally scaled currectly but it doesn't look as good as the original plus I'm concerned if sprites&textures are really the way.
happy new year
and thanks again
|
|
|
|
|
I'm trying to use the handy RemoteLib found on this site, but I cannot even get my linker to work right. I have added the .lib to my Project, as well as the folders containing the lib/headers to my linker/additional folder settings (at least i think i got the steps here right....). I #include'ed "RemoteLib.h" . I am using VC8 (visual studio 2005).
When I compile the RemoteLib example project I get (and similar in my own):
Linking...
DemoDlg.obj : error LNK2019: unresolved external symbol "struct
HINSTANCE__ * __cdecl RemoteGetModuleHandleNTW(unsigned long,wchar_t
const *)" (?RemoteGetModuleHandleNTW@@YAPAUHINSTANCE__@@KPB_W@Z)
referenced in function "protected: void __thiscall
CDemoDlg::OnCall(void)" (?OnCall@CDemoDlg@@IAEXXZ)
DemoDlg.obj : error LNK2019: unresolved external symbol "struct
HINSTANCE__ * __cdecl RemoteLoadLibraryNTW(unsigned long,wchar_t const
*)" (?RemoteLoadLibraryNTW@@YAPAUHINSTANCE__@@KPB_W@Z) referenced in
function "protected: void __thiscall CDemoDlg::OnCall(void)"
(?OnCall@CDemoDlg@@IAEXXZ)
RemoteLib: http://www.codeproject.com/dll/RemoteLib.asp?df=100&forumid=141663&exp=0&select=1008934&tid=1008934
Any suggestions would be appreciated
|
|
|
|
|
Have you added RemoteLib.lib to the Linker command line?
BTW Have you asked your son a bit turn on international politics (just kidding )?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
My command line looks like this
/OUT:"E:\code\sandapp\Debug\sandapp.exe" /INCREMENTAL /NOLOGO /LIBPATH:"E:\code\RemoteLib\RemoteLib_Bin" /MANIFEST /MANIFESTFILE:"Debug\sandapp.exe.intermediate.manifest" /DEBUG /PDB:"e:\code\sandapp\debug\sandapp.pdb" /SUBSYSTEM:WINDOWS /ENTRY:"wWinMainCRTStartup" /MACHINE:X86 /ERRORREPORT:PROMPT RemoteLIb.lib boost_regex_vc7_mss.lib
|
|
|
|
|
Good day,
I'm having a little trouble and I'm not even sure if this can be done.
I am writing a program that calls an HTTP address in order to generate a javascript object that then needs to be read. The Web address generates a file that looks like this:
obj = new Object();
obj.var1='abc';
obj.var2='def';
obj.var3='geh';
obj.var4='ijk';
Currently, I am just calling that page and reading it in as a text stream. Doing it this way, I'm going to have to parse through the string and separate all the values manually.
Code is as follows:
static const char s_szAgent[] = "";
CString str;
CString strURL = "http://mysite.com/js.go?var=test";
try
{
CInternetSession objSession(s_szAgent);
CHttpFile* pFile = (CHttpFile*)objSession.OpenURL(strURL, 1,INTERNET_FLAG_TRANSFER_ASCII | INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE);
// If open succeeded, read the file.
if (pFile)
{
CString strLine;
while (pFile->ReadString(strLine))
{
str+=strLine.Trim();
str+="\n";
}
pFile->Close();
delete pFile;
}
}
catch (CInternetException* pEx)
{
pEx->ReportError();
pEx->Delete();
}
Now my question is:
Is there a simpler way of doing this? Is there a way to just access that javascript object as a whole rather than just reading in a file string by string?
|
|
|
|
|
I guessing that, you talk about the ActiveX control usage. I have to been tried to ActiveX control to solve of the problem but I had no time to compile these codes:
<br />
CString strResult;<br />
m_strResult = strResult;<br />
TCHAR* ch = strResult.GetBuffer(strResult.GetLenght());<br />
CStdioFile sf(("HTML1.html", CFile::ModeRead());<br />
while(sf.ReadString("strResulte"))<br />
{ <br />
sprintf(string, "strResulte"); <br />
}<br />
CHttpFile* pFile;<br />
pFile->GetFileURL("c:\\Project\solution\res\html1.html");<br />
pFile->Open("\\res\html1.html", INTERNET_FLAG_RELOAD | INTERNET_FLAG_TRANSFER_ASCII , NULL);<br />
pFile->ReadString("strResulte"); <br />
pFile->GetObject(&strResult);<br />
pFile->classCStdioFile.CreateObject(&sf);<br />
pFile->classCFile.IsDerivedFrom(CHTMLView*); <br />
strResult.ReleaseBuffer();
Please, let me know if this idea can be helper.
Bitte tun Sie mir nicht antworten, wenn Sie nicht wissen, die Ursache des Problems wirklich oder nur als Antwort.
|
|
|
|
|
for (int i=0;i<largenum;++i) {<br="" mode="hold" /> try {} catch {}
}
Will the try...catch... hit the performance dramatically?
|
|
|
|
|
I think you have to reformat your OP.
Use the escape sequence for the < operator (i.e. < ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Have you performed a test with and without the try /catch code to see the difference?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
It works with sql server 2000.
But without the try...catch... the codes changed.
However, the try...catch... version is about 10% slow.
All because I insert strings to sql server 2000, and the string many contains singal quotation(s).
|
|
|
|
|
You can have VC++ generate an ASM listing file.
Maxwell Chen
|
|
|
|
|
Hello everyone,
Why visual studio does not optimize constructor in this case? I do not understand what the MSDN mentioned,
if use different named object, compiler can not optimize. Why?
http://msdn2.microsoft.com/en-us/library/ms364057(vs.80).aspx
class RVO
{
public:
RVO(){printf("I am in constructor\n");}
RVO (const RVO& c_RVO) {printf ("I am in copy constructor\n");}
int mem_var;
};
RVO MyMethod (int i)
{
RVO rvo;
rvo.mem_var = i;
if (rvo.mem_var == 10)
return (RVO());
return (rvo);
}
int main()
{
RVO rvo;
rvo=MyMethod(5);
}
Output is,
I am in constructor
I am in constructor
I am in copy constructor
My expected output is,
I am in constructor
I am in constructor
thanks in advance,
George
|
|
|
|
|
does this limitation applies in your case ?
Multiple return paths (even if the same named object is returned on all paths) with EH states introduced.
There are 2 return paths in your MyMethod .
|
|
|
|
|
Thanks Maximilien,
What means EH states?
I do not know why diferent execution path will disable compiler from optimization. In the sample, there are two execution paths to return,
1. return (RVO());
In case (1), compiler could optimize by saving the creating of the temporary object and assign to the extern rvo object directly.
2. return (rvo);
In this case (2), compiler could optimize by not creating the temporary object for the return value, and assign the inner rvo to outter rvo directly.
Why compiler can not optimize it?
regards,
George
|
|
|
|
|
George_George wrote: What means EH states?
The exception handling state.
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I have provided my perpective below why the compiler should be able to optimize the code, and it is appreciated if you could review and comment.
regards,
George
|
|
|
|
|
"Named Return Value Optimization" is mainly Stan Lippman's work. As you have read that there are three exceptions which NRVO do not take place.
Different paths returning different named objects.
Multiple return paths (even if the same named object is returned on all paths) with EH states introduced.
The named object returned is referenced in an inline asm block.
Let's see your example (example 7 in MSDN). In function RVO MyMethod(int i) , there are two return paths (see below). They are different intermediate object names. The compiler can not simplify these two return path into one.
RVO MyMethod (int i){
RVO rvo;
rvo.mem_var = i;
if (rvo.mem_var == 10)
return (RVO());
return (rvo);
}
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I can understand the real path for execution could only be decided at runtime.
But I do not know why which named variable/return path matters the optimization -- the optimization only happens when the function returns and compiler only needs to insert optimization code at the place where there is a return statement -- if there are multiple returns, the compiler could put multiple optimization into multiple return statement.
I think no matter which one will return, either rvo or RVO(), the return value is a temporary obejct, and compiler could optimize it by using assignment operator on the outside rvo object instance directly without creating the temporary object, right?
Why the named variable/return path matters? Could you provide more information about your analysis please?
regards,
George
|
|
|
|
|
George_George wrote: But I do not know why which named variable/return path matters the optimization
The term "optimization" refers to two aspects: (1) efficiency , and (2) code size .
(1) The efficiency concept: Just like finding the shortest path.
(2) The code size issue: If many return paths can be simplified, concluded, and compacted into one single return path, the code size will be smaller. And maybe it would be more efficient.
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
I think you mean there is room for compiler to optimize the speed of the code, but considering the binary size will be larger, the code can not be optimized, right?
But I am confused that I assign the /O2 (optimize for max speed) and it should work and does not consider the resulting binary size -- which is the purpose of /O1 (optimize for small size). Any comments?
regards,
George
|
|
|
|
|
George_George wrote: RVO rvo;
rvo.mem_var = i;
if (rvo.mem_var == 10)
return (RVO());
return (rvo);
IMHO, In this case the optimization will be difficult and sometimes useless. That may be the reason the code goes untouched.
Suppose the return value pass by hidden reference,as per the article,
1. If value of i == 10, it have to construct/copy the return value once again after initialization as the newly cosntructed object depends on another location of memory. which gives no advantage on optimization
2.As per the article, the NRVO is basically on workes with single return objects.
In the following case, the optimization dint work.
RVO rvo;<br />
<br />
if ( 11 == 10)<br />
return (RVO());<br />
rvo.mem_var = i;
return (rvo);
In the following case compiler damn sure that
if ( 11 == 10)<br />
return (RVO());
The above case will never works, so NRVO can be applied but still it's missing I believe.
Anyway I'm not so expert in optimization related things, please share you view points.
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Thanks for sharing your perpective, Sarath!
Two more comments,
1. I do not quite understand why you think below in the case there is no room to optimize? Could you provide more description please?
Sarath. wrote: 1. If value of i == 10, it have to construct/copy the return value once again after initialization as the newly cosntructed object depends on another location of memory. which gives no advantage on optimization
2. here is my perpective mentioned before, please feel free to comment and correct.
--------------------
I do not know why which rvo instance will return matters. I think no matter which one will return, either rvo or RVO(), the return value is a temporary obejct, and compiler could optimize it by using assignment operator on the outside rvo object instance directly without creating the temporary object, right?
Why the path matters? Could you provide more information about your analysis please?
--------------------
regards,
George
|
|
|
|
|
George_George wrote: 1. I do not quite understand why you think below in the case there is no room to optimize? Could you provide more description please?
Sarath. wrote:
1. If value of i == 10, it have to construct/copy the return value once again after initialization as the newly cosntructed object depends on another location of memory. which gives no advantage on optimization
I was talking based on the article.
Please check Hidden argument with/without NRVO[^]
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|