473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Prevent memory from being changed while it's in use

Frinavale
9,735 Expert Mod 8TB
I have a problem and I don't know why I'm having such a hard time solving it.

The problem comes from a VB6 COM object that raises an event periodically. The call back method for the event (the method that handles the event) has a strange signature. It looks like this:

onTheEvent(ByRef x As AStructureType, ByRef y As Boolean)

I need to retrieve the information stored in "x" but sometimes the next event is raised before I can retrieve this information. Since it's being passed in ByRef the underlying memory for the structure is changed and ...well...things get really messed up.

How do I prevent the memory from being changed by the COM object (lock it) while I am using that memory?

(PS...if you haven't already gathered, it's a Structure, not an Object that I'm working with)

Thanks,

-Frinny
Jun 1 '10 #1
6 1310
Frinavale
9,735 Expert Mod 8TB
I've been trying to find information on how to copy the structure so that I'm not always pointing to the same memory location.......I am not having any luck with this though.

The data is changed if I try a member-by-member copy in my .NET code....which means the copy will not work.

*Frustrated!*

-Frinny
Jun 1 '10 #2
Plater
7,872 Expert 4TB
Yeah generally I would say the first thing you should do is copy the struct data to a local variable.
However you go about doing that. (Is it as simple as declaring a new var and using the = operator?)
Jun 1 '10 #3
Frinavale
9,735 Expert Mod 8TB
It would be as simple as declaring a new assignment operator except that I don't have access to the code where it should be implemented (the VB6 code).
Jun 2 '10 #4
Plater
7,872 Expert 4TB
Ok so the event and its handler are all raised INSIDE the COM object then?
Jun 3 '10 #5
Frinavale
9,735 Expert Mod 8TB
The event is raised by the COM object.

My code handles the event that is raised but it is passed a variable ByRef. This means that the next time the event happens the memory is changed even though I'm in the midst of using it.

I tried using reflection to copy the Structure but I found it was too slow, the next event was raised before it could complete (when you first start receiving events a Whole bunch of them are sent to you extremely quickly).

I changed my code so that it didn't use reflection and things have been working without incident so far (on my development machine)...not sure how it will fair on a faster, better machine.

-Frinny
Jun 4 '10 #6
Plater
7,872 Expert 4TB
Right, thats what i thought the handler is in your managed code.
So couldn't you copy the value in the handler?
Just like when working with threads, make a local copy imediately?
Jun 4 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Dave Smithz | last post by:
Hi there, Users of my PHP DB application have complained that it seems to log them out every now and then. I actually assume this is when it has been idle for sometime as I use session variables...
4
by: BluDog | last post by:
Hi I have a basic UserControl that i want to be able to prevent controls being added to, i was thinking about catching the ControlAdded event and then removing the control immediatley after, but...
9
by: MR | last post by:
Why does the string value assigned to the RequestElementName in the SoapDocumentMethodAttribute get changed? The value below with a colon is changed to the hex value surrounded by underscores....
0
by: Uwe Mayer | last post by:
Hi, I am wrapping a C function returning large amount of binary data back to Python using SWIG. I have the data malloc()ed or new()ed on the heap and buffer objects seem a good way to wrap it...
6
by: zl2k | last post by:
hi, When I considered about preventing memory leaking, the method came up to my mind is using boost smart pointer if possible (use stl::vector instead of type, use smart pointer whenever declare...
1
by: crka.crka | last post by:
Does anyone know a way to prevent a file being deleted so the only way to delete is via unistallation? Help would be very much appreciated.
2
by: Sandra-24 | last post by:
How can you prevent self from being passed to a function stored as a member variable? class Foo(object): def __init__(self, callback): self.func = callback f =Foo(lambda x: x) f.func(1) #...
1
by: turnitup | last post by:
Dear All, I have a slight problem, even though I have set up a discrete session path with write access, and my session files are being set there, users still get intermittently "kicked off",...
1
by: Randy | last post by:
I'm using VS 2003. I have a c# ASP project. Lately, when I've been running the project in the IDE, I get a dialog which says... "This source file has changed. It no longer matches the version of...
13
by: frozenade | last post by:
dear all.. I try an upload script from: http://www.phpletter.com/uploaded/projects/ajaxfileupload/ajaxfileupload.zip in online demo page, it's ok, but when I downloaded it and try to localhost,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.