|
When you allocate a chunk of memory, what you get is a memory chunk at least as big as what you requested, and some extra data. The whole chunk looks like this:
[ Extra Data ][ Your data - X bytes ] The pointer which new returns, is the adress of the first byte of [ Your data ]. The [ Extra Data ] chunk is used later on when you deallocate the memory. When you pass a pointer to delete for deallocation, delete will actually "step back" and take a peek at what's inside [ Extra Data ]. That chunk of data contains book keeping information about the memory allocation - which it really needs to be able to put the allocated memory back into the pool of unallocated memory.
If you increment the pointer value, it will no longer point to the beginning of the data chunk which new returned. So when you pass the modified pointer to delete, it will not find the book keeping information when it "steps back". It will find data from which you put into your data chunk, which delete will interpret as garbage...
--
Torn from tomorrow's headlines
|
|
|
|
|
HI,
Anyone knows if there's any way I can track if the system clock on a Windows OS has been changed, without having to run an application all the time? I mean if there's any history log I can call some function to retrieve?
Thanks!
d8
|
|
|
|
|
dummy808 wrote: Anyone knows if there's any way I can track if the system clock on a Windows OS has been changed...
You mean other than the change that occurs every second?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
It's possible there's an entry made in the system event log when someone changes the system clock. I doubt that it's documented, however.
Software Zen: delete this;
|
|
|
|
|
Using VC6
I have a (static, one column, two rows) splitter window in an app I'm working on. I need to make the splitter bar taller and put text in it. I've created a class derived from CSplitterWnd and overridden the OnDrawSplitter function, but nothing I've tried makes the bar any taller.
Can anyone provide assistance?
-----------
Found the answer in the CFlatSplitterWnd article here on CP.
-- modified at 14:08 Friday 8th September, 2006
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Until now I was using Visual Studio 6 to code a program in c++. Recently I downloaded the Visual C++ 2005 Express Edition from microsoft's web site and I'm having trouble using it. I open a project from VS 6 and I can't find the dialogs I had created. But more important is that the project cant be built..!
Anyone to put me out of me misery?
|
|
|
|
|
When VS 2003/2005 loaded a VC 6 project, it will ask if you wanted to convert the project to the new platform. Did you allow the conversion?
Best,
Jun
|
|
|
|
|
|
Visual C++ Express is a free version, thus it doesn't contain all the functionalities. There is no MFC and no resource editor (that's why you cannot find your dialogs). So, if your project was using MFC in VC6 (which probably the case), you won't be able to compile your project.
|
|
|
|
|
Cedric Moonen wrote: ...and no resource editor...
Just out of curiosity, how does one go about editing resources? An external utility?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yes, there are some free utility, but I cannot find the link anymore . It was called ResEd (resource editor). Of course this is not as good as the one included in visual studio.
|
|
|
|
|
Visual C++ Express sucks
Best,
Jun
|
|
|
|
|
Not sure about the etiquette there - am I supposed to cross-post questions if my project covers more than one forum? if I am wondering, it probably mean it is a bit rude... I promiss that however desperate I get (and I am) I will not spam the lounge though. OK anyway, here is the reason of my misery:
In an asp.net application, I use a COM object... this COM objects is stored in the session.
The COM object has methods that can last a long time (it sends info through a socket and wait for the reply). My problem is whenever I call a method of the COM object, it is always in the same thread which means that multiple users can block themselves out ( I know: I log the thread ID).
The COM threading model is apartment.... which should be OK.
All threads in asp.net are MTA.... which should be OK.
But the whole thing is not OK.. any idea? Thanks!
|
|
|
|
|
|
Thanks for this - but my object is not STA but MTA... I checked this in the registry... the threading model is apartment!
|
|
|
|
|
Do you have access to the code for the COM classes? - or are you building around it with no clue as to how it works? In MTA the COM object performs the synchronization.
A cynic is a man who, when he smells flowers, looks around for a coffin. -H.L. Mencken
|
|
|
|
|
Yes I have the source code for the COM object : I programed it as well - that does not obligatory mean I have a clue though...
|
|
|
|
|
Geez OK well this is my somewhat limited take on it. My understanding is that in STA it acts like a UI - it responds to input, while in the MTA it is internally handled - Are you sure you need MTA?
STA can handle multiple threads it is just that there one to one relationship between the apartments and the threads. In MTA the threads are sort of like in a mixed bag that you are required to do some extra coding for. I am not sure what the exact problem if you are always coming up the same thread - can you clip some code that shows the getting of the thread / thread pointer?
You might be interested in this article:
COM Apartments and .NET Threads[^]
-- modified at 15:18 Friday 8th September, 2006
A cynic is a man who, when he smells flowers, looks around for a coffin. -H.L. Mencken
|
|
|
|
|
Not sure if I need MTA or STA, what I need is that calls from different internet sessions have their own thread when they arrive in the COM object... It seems crazy that the same thread would be resued within the COM Object. Well well...
I did read the article aearlier today googling about... it seems like the ASP.net code is ints own thread pool but not within the COM object...
Ahhhhhh... I am going mad!
Thanks for your help, brother !
|
|
|
|
|
What is wrong with the following code? (it's homework, but I couldn't figure out anything)
#include <assert.h>
class Object
{
public:
Object () : pAlive (new bool (true)) {}
~Object () { assert (*pAlive); * pAlive = false; delete pAlive; }
private:
bool * pAlive;
}; // Object
int main()
{
Object x1, x2;
x1 = x2;
return 0;
}
Jon
|
|
|
|
|
There will be a memory leak. x1 and x2 both declare a boolean variable on the heap. Since Object doesn't have a copy-constructor/assignment operator, it uses the implicit one that will copy the value of the pointer from x2 to x1. Thus, the data that x1's original pointer was pointing to is still allocated, but has no way of getting access to it to delete it.
Worse, if the line *pAlive = false; is not there, the code will actually cause memory corruption since x1 and x2 will both have pointers to the same boolean variable and will both try to delete it.
NOTE: In general, I wouldn't answer homework questions this thoroughly ... but I'm feeling generous today.
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
|
|
|
|
|
jon_80 wrote:
x1 = x2;<pre>
after this line (x1.pAlive == x2.pAlive)
once destructor on the first one has been called, pAlive of otherone is a dangling pointer(location to which it points is no longer valid). hence the assertion fails.
OT: learn to use a debugger.
|
|
|
|
|
If this is not a homework problem get rid of the pointers, the new and the delete as there is no good reason to dynamically allocate and use a 32 bit value in this way.
John
|
|
|
|
|
John M. Drescher wrote: If this is not a homework problem
He did state that it was a homework problem ...
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
|
|
|
|
|
Hi everyone,
I want to use m_hDC in CImage class but when i write m_image.m_hDC; i get this error:
error C2248: 'ATL::CImage::m_hDC' : cannot access private member declared in class 'ATL::CImage'
is it possible to use private members in this class
Thanks
|
|
|
|