|
Sarath. wrote: int* p1 = new int[0];
That line will actually cause a memory corruption. It has been mentioned that the compilers should treat this as an error when the new standard is released, but if you try it on certain compilers right now, it won't give you an error. If you do it with Microsoft's compiler, you usually get a weird looking message box that pops up and tells you that the memory has been corrupted.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Anyway it's returning a valid pointer. my question was, will this create a memory leak? (if we don't call delete.anyway if we call delete it will fail)
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
Sarath. wrote: Anyway it's returning a valid pointer
No, its not valid pointer.
operator new allocates additional memory on heap , when we use it. It contains header info and bytes to guard off memory, called 'No Mans land'.
So actual size will be,
actual_size=sizeof(headerinfo)+nSizeRequestedbyUs+NOMansLandSize
In above case though nSizeRequestedbyUs is 0, it returns valid address, but not supposed to access by us.
Sarath. wrote: will this create a memory leak? (if we don't call delete.anyway if we call delete it will fail)
Yes.
By accessing it we are corrupting it. So giving error while deletion.
If you try to delete it without accessing it , ie. without assigning any value to it, it will not give you error.
-- modified at 2:57 Thursday 3rd August, 2006
|
|
|
|
|
Sarath. wrote: Anyway it's returning a valid pointer.
On the VC6 compiler, the line with new int[0] would cause an immediate crash in both release and debug builds. I'm not sure if the newer compilers still do that, but the line is invalid code. If the pointer that comes back looks valid, I assure you, it isn't. You are guaranteed to corrupt your memory by writing to the location it gives you.
Sarath. wrote: my question was, will this create a memory leak?
You won't get a memory leak, you get memory corruption. Basically, the line itself causes a problem, and deleting it is the least of your worries (calling delete won't fix the memory problem you created by trying to declare a 0-sized array).
In general, think logically when programming. It makes no sense to have an array with no capacity; therefore, it is not valid to declare.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Sarath. wrote: 1. Why a size of an empty class is 1 byte?
See here.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I have a dialog based app and would like to have another dialog be anchored to either the bottom or the left side of my main dialog. Can someone please point me to some code for this, or help me? I figured I should be using SetWindowPos(), but how do I know where to place it?
Thanks in advance.
|
|
|
|
|
- Handle the
WM_MOVE notification in your main dialog.
- Compute your main window's bottom-L corner.
- Call
MoveWindow() or SetWindowPos() on the secondary dialog. /ravi
|
|
|
|
|
IN addition to Ravi's reply, you may have to use modeless dialog
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
yes, I'm sorry. The second dialog I am trying to use is a modeless dialog that is show when a menu item is selected.
can someone help me calculate the size of my main dialog?
|
|
|
|
|
GetClientRect and GetWindowRect are at your disposal
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
NYTSX wrote: calculate the size of my main dialog?
GetWindowRect()
/ravi
|
|
|
|
|
I have a many C++ windows projects, dlls and librarys. I have done some research to find out what happens if there are similar string IDs in projects, dlls and libraries after they are are linked together.
What happens is the string in the project always replaces the string in the dll or library if there is a string ID match.
Example: I declare string ID 100 as "Chris" in the project, "John" in the dll, and "Bob" in the library. I use CString::LoadString(100) in the dll and CString::LoadString(100) in the library. When these two statements are executed the string "Chris" is loaded from the project string table and not the library and dll.
I was able to solve the similar string issue between projects and dlls useing ::FindResource along with the dlls instance. Has anyone figured out how to have similar strings between projects and libraries?
Chris
|
|
|
|
|
|
So how do you get the instance of a library?
Chris
|
|
|
|
|
See this[^] article.
/ravi
|
|
|
|
|
I read the article and there is no mention of a library project. This article deals with string conflicts in DLL projects. My issue is having similar strings with a library project where there is a DLL is not created.
Chris
|
|
|
|
|
You are creating static link libraries with resources in them?
The problem you are having deals with search order. It is very similar to dealing with a PATH variable. The LoadString method looks in its module for a string id. If it finds it, it uses it. Otherwise, it moves on to the static libraries that were compiled into your project (which really shouldn't have resources of their own, but I digress). Finally, it starts marching through the DLLs you have loaded.
This is why you should make sure that your string IDs are unique.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
So there is no way to have the same string id in a project and in a library and have the library string "Win".
Chris
|
|
|
|
|
The reason I am asking this question in the first place is because I have three different languages in all the projects, libraries and dlls. That is why I have string resources in libraries.
Chris
|
|
|
|
|
The better way to handle that case is to make each language its own resource dll and to allow the user to select which language they want to use (or detect what Windows is using when the application starts up). Then you would just load that DLL. There is an example of how to do that in an article on this site (I believe it is in the DLL section).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
It almost sounds like you need AFX_MANAGE_STATE(AfxGetStaticModuleState()) at the top of the routine that calls LoadString() . This is just a guess, however.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
This looks very interesting. I have never used AFX_MANAGE_STATE(AfxGetStaticModuleState()) before. I am not useing LoadLibrary() anywhere in the projects. I just put the library location in the linker of Microsoft Visual Studios 6.0. Also I wonder if AFX_MANAGE_STATE would even work because the description of this macro is "Call this macro to protect an exported function in a DLL." I am not sure if this would work with a library or not.
Chris
|
|
|
|
|
chris175 wrote: I am not useing LoadLibrary()...
I meant LoadString() .
chris175 wrote: Also I wonder if AFX_MANAGE_STATE would even work...
It very well may not. Your problem just sounded like one that the macro was designed to resolve (e.g., a DLL and an EXE both having a like-numbered resource, but the wrong one gets loaded).
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Does anyone know of a sample MS Visual C++ program that takes raw black and white video data (saved as a binary file) that is transmitted at 3 frames/sec and shows them on the screen at the same rate?
if not, is there an article that explains how to do this in Visual C++?
thanks in advance.
-- modified at 10:10 Wednesday 2nd August, 2006
Kitty5
|
|
|
|
|