|
kitty5 wrote: UCHAR *buff[3];
buff[0] = new UCHAR[45000000];
buff[1] = new UCHAR[45000000];
buff[2] = new UCHAR[45000000];
when I do:
ReadFile(...,...,buff[num],...,NULL);
buff is an array of 'size' 3 and each cell in the array contain a pointer (and each of these pointers point to an array of 45000000 UCHAR). When you do do buff[num] , if num is higher than the size of your array (3 in this case), you write to an invalid address.
By the way, allocating 3 times 45000000 is quite big. Are you sure you want to allocate so much memory ?
|
|
|
|
|
kitty5 wrote: buff[num]+= 2028;
that's a bad idea. since you haven't stored the pointer in buff[num] anywhere else, you won't be able to free buff[num] later. you should make a copy of buff[num] so you'll be able to delete it when you're done.
kitty5 wrote: //increment the pointer to the next chunk
how many 'chunks' do you get before the error happens ?
|
|
|
|
|
kitty5 wrote: buff[num]+= 2028;//increment the pointer to the next chunk
You can't do this and expect to be able to delete the memory. The statement buff[0] = new UCHAR[45000000] assigned a specific memory address to buff[0] . If you advance that address by 2048 bytes, the delete operator will fail. Try:
ReadFile(..., buff[num]+offset, ...);
offset += 2048;
"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
|
|
|
|
|
DavidCrow wrote: You can't do this and expect to be able to delete the memory. The statement buff[0] = new UCHAR[45000000] assigned a specific memory address to buff[0]. If you advance that address by 2048 bytes, the delete operator will fail. Try:
ReadFile(..., buff[num]+offset, ...);offset += 2048;
isn't:
offset = 2028;
ReadFile(..., buff[num]+offset, ...); not the same as:
offset = 2028;
buff[num]+= offset;
ReadFile(..., buff[num], ...);
either way you are advancing the address by 2028?
Kitty5
|
|
|
|
|
One actually advances the pointer, while the other does not. That's the distinction.
"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
|
|
|
|
|
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
|
|
|
|