Re: Pointer operations
From: TVR Fan (nosuch_at_address.com)
Date: 06/07/04
- Next message: Jonathan Arnold: "Re: Executable Name of Windows Application"
- Previous message: Pat Crowe: "Re: Read a jpg file"
- In reply to: Scott McPhillips [MVP]: "Re: Pointer operations"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 7 Jun 2004 13:46:17 +0100
"Scott McPhillips [MVP]" <scottmcp@mvps.org.nothere> wrote in message
news:eIBsabITEHA.3720@TK2MSFTNGP10.phx.gbl...
> Macca wrote:
> > Hi,
> >
> > I have created a pointer in a class A (Dialog class) on heap using new.
This pointer is of type Class B and does various data processing. Now there
is a variable in Class B that i want to be able to manipulate from another
dialog Class C.
> >
> > This variable will be accessed in Class A and Class C.
> >
> > The way i was going to do this was to pass the pointer created in Class
A ( using Lparam of SendMessage Call )to Class C. Class C would be able to
change the state of this variable.
> >
> > My worry is that this method could cause problems. e.g class A and C
accessing variable at the same time.
> >
> > Is the way im proposing valid?
> >
> > I'd appreciate opinions,
> >
> > Thanks
> > Macca
>
> Class A and C can not access a variable at the same time unless they are
> executing in different threads. If you have not created multiple
> threads then there is no problem.
>
> --
> Scott McPhillips [VC++ MVP]
>
I believe its also good programming practice for class B to provide public
functions for manipulating the variable. The variable can then be made
protected and its implementation can change without affecting classes C and
A.
For example if, later on, you change the code so that classes C and A can be
running in separate threads, then you will need to protect the variable with
a mutex. If you've provided functions in class B to access the variable,
then the access functions can use the mutex internally and classes A and C
may not need to change.
--- Al.
- Next message: Jonathan Arnold: "Re: Executable Name of Windows Application"
- Previous message: Pat Crowe: "Re: Read a jpg file"
- In reply to: Scott McPhillips [MVP]: "Re: Pointer operations"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|