Re: Pointer operations

From: TVR Fan (nosuch_at_address.com)
Date: 06/07/04


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.



Relevant Pages

  • Re: Why is Marcia here?
    ... Please provide a pointer to the thread ... manipulate and lie in order to discredit people who take ... your personality disorder is so deeply ingrained ... of medication. ...
    (misc.health.alternative)
  • Re: why the usage of gets() is dangerous.
    ... object files with 64-bit libraries, ... memory model object files with large memory model libraries. ... We're talking about use of fat pointers as a device to protect against ... relatively straightforward fat pointer implementation that is ...
    (comp.lang.c)
  • Re: wm_message
    ... invoke the dialog with DoModal, and if it exits with IDOK, I will obtain the values from ... void GetParameters; ... I try to avoid ever having a pointer to a document in a dialog. ... If you want to be able to manipulate the object in both the dialog and the document, ...
    (microsoft.public.vc.mfc)
  • Re: why the usage of gets() is dangerous.
    ... object files with 64-bit libraries, ... memory model object files with large memory model libraries. ... A bullet-proof vest won't protect against a head shot, washing your hands before a meal won't protect you against airborne diseases, the best available contraceptive measures still occasionally fail. ... relatively straightforward fat pointer implementation that is only moderately inefficient can't protect against every possible problem. ...
    (comp.lang.c)
  • Re: wm_message
    ... Well I have decided to initialize the pointers from the view without using ... messaging. ... I try to avoid ever having a pointer to a document in a dialog. ... If you want to be able to manipulate the object in both the dialog and the document, ...
    (microsoft.public.vc.mfc)