 |
|
|
|
| Author |
Message |
Chetan Raj
Joined: 04 Oct 2007 Posts: 2
|
Posted: Thu Sep 02, 2004 11:56 am Post subject: SafeArrayLock Why is it Required |
|
|
Hi All,
Basic questions...
Why do we need SafeArrayLock? Can't we directly access the pointer
pvdata? What issues will arise if I directly use pvdata as shown...
(m_pSa->pvData)[index] = nDirection
where m_pSa is a SafeArray of integer?
Thanks,
Chetan
Archived from group: microsoft>public>vc>atl |
|
| Back to top |
|
 |
Igor Tandetnik
Joined: 04 Oct 2007 Posts: 26
|
Posted: Thu Sep 02, 2004 3:07 pm Post subject: Re: SafeArrayLock Why is it Required |
|
|
"Chetan Raj" wrote in message@posting.google.com
> Basic questions...
> Why do we need SafeArrayLock?
Almost never needed. I never had a chance to use it. A locked array
cannot be freed or resized, which guarantees that the raw data pointer
does not change under you. However, this is only useful if you cache the
raw pointer, which is quite an unusual thing to do.
> Can't we directly access the pointer
> pvdata?
You can. Personally, I prefer to treat SAFEARRAY as an opaque data
structure, and use public APIs to manipulate it. Also, I'm not sure what
SafeArrayLock has to do with pvData - are you maybe thinking of
SafeArrayAccessData?
> What issues will arise if I directly use pvdata as shown...
>
> (m_pSa->pvData)[index] = nDirection
>
> where m_pSa is a SafeArray of integer?
It won't compile - you cannot apply subscript operator to a void*
pointer. You need to cast it appropriately.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken |
|
| Back to top |
|
 |
Chetan Raj
Joined: 04 Oct 2007 Posts: 2
|
Posted: Fri Sep 03, 2004 2:31 am Post subject: Re: SafeArrayLock Why is it Required |
|
|
Thanks for your reply,
<<<
Can't we directly access the pointer pvdata?
>>>
Here, I had meant that is it safe enough to access raw pvdata without
applying any locks either through SafeArracyAccessData or
SafeArrayLock APIs?
Now does,
((int*)(m_pSa->pvData))[index] = nDirection
have any undefined behaviour?
Thanks,
Chetan
"Igor Tandetnik" wrote in message news:...
> "Chetan Raj" wrote in message
> @posting.google.com
> > Basic questions...
> > Why do we need SafeArrayLock?
>
> Almost never needed. I never had a chance to use it. A locked array
> cannot be freed or resized, which guarantees that the raw data pointer
> does not change under you. However, this is only useful if you cache the
> raw pointer, which is quite an unusual thing to do.
>
> > Can't we directly access the pointer
> > pvdata?
>
> You can. Personally, I prefer to treat SAFEARRAY as an opaque data
> structure, and use public APIs to manipulate it. Also, I'm not sure what
> SafeArrayLock has to do with pvData - are you maybe thinking of
> SafeArrayAccessData?
>
> > What issues will arise if I directly use pvdata as shown...
> >
> > (m_pSa->pvData)[index] = nDirection
> >
> > where m_pSa is a SafeArray of integer?
>
> It won't compile - you cannot apply subscript operator to a void*
> pointer. You need to cast it appropriately. |
|
| Back to top |
|
 |
Igor Tandetnik
Joined: 04 Oct 2007 Posts: 26
|
Posted: Fri Sep 03, 2004 2:20 pm Post subject: Re: SafeArrayLock Why is it Required |
|
|
"Chetan Raj" wrote in message@posting.google.com
> <<<
> Can't we directly access the pointer pvdata?
>>>>
>
> Here, I had meant that is it safe enough to access raw pvdata without
> applying any locks either through SafeArracyAccessData or
> SafeArrayLock APIs?
>
> Now does,
>
> ((int*)(m_pSa->pvData))[index] = nDirection
>
> have any undefined behaviour?
I don't see any problem with this. Again, personally I prefer using
SafeArrayAccessData, but YMMV.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
|
|
| Back to top |
|
 |
|
|
| Related Topics: | ADO help required I have been going around in circles trying to understand the method of creating a database in VB.Net 2003 and distributing that application and database. It seems if I use the Server Explorer to create the etc, the link to the database wor
Desperate Help required - Adding a block of data Hi all, I am trying to add a block of cells but sadly can't get excel VBA to exactly read my intentions. I really wish cells H8 to H12 to be totalised but using the following statement the formula returns "Sum(H1:H12) row_no = ActiveCell.Of
VB6 Help Required Hi there, I'm trying to pass a variable to a field name, as illustrated using: Dim FieldName as String FieldName = "" = "" (i.e. I want RecordName's FieldName to be able to be declared - this is so that I can use it as procedure inste
Help Required Hi I use the following code to retrieve a stored Path in the registry and put the Path in a Textbox:- Private Sub Form_Load() Drive1.Drive = "Path", "drive", "c:") Dir1.Path = "Path", "folder", "\") txtPath
Direct X 9.0c required Already had DirectX 8 installed but when recently installed 9.0c i get critical error message saying "Direct X 9.0c or higher required!" every 1 minute intervals and i had constantly need to click on ok button and if i do not... it freezes the screen unt |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|