LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arrays and pointers

hello

i'm having trouble with arrays, pointers, and releasing them in CINs.. First
off, i'm following the example in the Code Interface Reference Manual 2-18
(pg 70). In this example, they manipulate arrays by having a pointer point
to the first element of the array that the handle it pointing to: float32
*aElmtp; aElmtp = (*ah) -> arg1; (where ah is the name of the handle of the
array being passed into a CIN)

I did this and it seemed to work for a while but then i kept on getting
Application errors in windows NT. It said that it couldn't write to a memory
space that it was referencing. Later on, i saw on 5-10 pg 121 of the same
manual that DSNewPtr would help out if there were memory problems.. this
works fine except now the progr
am crashes whenever i try to use DSDisposePtr
to release the pointers.. and if i don't use it, the program crashes every so
often because the memory gets full.. I'm passing in 3 arrays into the CIN and
therefore creating and trying to dispose of 3 pointers. i debugged the CIN
and it crashed every time at the DSDisposePtr. can anyone help? i am using
Labview 5.1.1 in Windows NT. Thank you for your input.

Eugene Kim


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 1 of 6
(3,207 Views)
> i'm having trouble with arrays, pointers, and releasing them in CINs.. First
> off, i'm following the example in the Code Interface Reference Manual 2-18
> (pg 70). In this example, they manipulate arrays by having a pointer point
> to the first element of the array that the handle it pointing to: float32
> *aElmtp; aElmtp = (*ah) -> arg1; (where ah is the name of the handle of the
> array being passed into a CIN)
>
> I did this and it seemed to work for a while but then i kept on getting
> Application errors in windows NT. It said that it couldn't write to a memory
> space that it was referencing. Later on, i saw on 5-10 pg 121 of the same
> manual that DSNewPtr would help out if there were memory problems.. this
> works fine except now the program crashes whe
never i try to use DSDisposePtr
> to release the pointers.. and if i don't use it, the program crashes every so
> often because the memory gets full.. I'm passing in 3 arrays into the CIN and
> therefore creating and trying to dispose of 3 pointers. i debugged the CIN
> and it crashed every time at the DSDisposePtr. can anyone help? i am using
> Labview 5.1.1 in Windows NT. Thank you for your input.
>

Any number of things could be going wrong. If arrays or strings are
being passed
into the CIN from the diagram, then you shouldn't be disposing of these.
You can
change the number of elements in them, but do not dispose. Also, it
isn't clear
what you are doing with DSNewPtr. None of the types passed into the CIN
will be
pointers. They will be pointers to Handles. You can use
DSSetHandleSize to change
the size of the Handles, but you shouldn't delete anything. If you are
using the
DSNewPtr and DSDisposePtr just for temporary storage, then that is
totally OK,
and should be dele
ted. You might want to make sure that the value
passed into
DSDisposePtr is exactly what was returned from DSNewPtr. Any difference will
cause problems.

Greg McKaskle
0 Kudos
Message 2 of 6
(3,207 Views)
Eugene,

I poorly have understood an exact sense of problem. There are no
problems with using pointers manipulation routines in CINs (certainly
if you use correct values of arguments). However arrays are passed to
CIN via handles and if you want to manipulate with sizes of these
arrays you should use SetCINArraySize or NumericArrayResize routines.

If you could send a small C code illustrating the trouble, I would have
more possibilities to help you.

Regards,
Kostya.


In article <8lqarr$855$1@nnrp1.deja.com>,
eugenekim@my-deja.com wrote:
> hello
>
> i'm having trouble with arrays, pointers, and releasing them in CINs..
First
> off, i'm following the example in the Code Interface Reference Manual
2-18
> (pg 70). In this example, they manipulate arrays by hav
ing a pointer
point
> to the first element of the array that the handle it pointing to:
float32
> *aElmtp; aElmtp = (*ah) -> arg1; (where ah is the name of the handle
of the
> array being passed into a CIN)
>
> I did this and it seemed to work for a while but then i kept on
getting
> Application errors in windows NT. It said that it couldn't write to
a memory
> space that it was referencing. Later on, i saw on 5-10 pg 121
of the same
> manual that DSNewPtr would help out if there were memory problems..
this
> works fine except now the program crashes whenever i try to use
DSDisposePtr
> to release the pointers.. and if i don't use it, the program crashes
every so
> often because the memory gets full.. I'm passing in 3 arrays into the
CIN and
> therefore creating and trying to dispose of 3 pointers. i debugged
the CIN
> and it crashed every time at the DSDisposePtr. can anyone help? i am
using
> Labview 5.1.1 in Windows NT. Thank you for your input.
>
> Eugene Kim
>
> Sent via Deja.
com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 3 of 6
(3,207 Views)
Thanks for responding, Greg and Kostya.

the exact bit of code was:


int32 *Analogs;
Analogs = (int32 *)DSNewPtr(sizeof(int32));
Analogs = (*var1)->_0_V_Power_Supply_VDC_;
/*
.
array operations
.
*/
DSDisposePtr(Analogs);

when i debugged the CIN using DebugBreak, it always crashed at the
DSDisposePtr(Analogs);. i guess that's because i was trying to delete
(*var1)->_0_V_Power_Supply_VDC_ instead of the pointer Analogs? my
program seems stable if i get rid of the DSDisposePtr... but is this ok?
do i even need the DSNewPtr? if i leave this around will it end up
leaking a whole lot of memory or will NT be able to clean it up after LV
is closed?

Thanks again

Eugene



In article <8lr4sm$qc8$1@nnrp1.deja.com>,
Kostya wrote:
> Eugene,
>
> I poorly have understood an exact sense of problem. There are no
> problems with using pointers manipulation routines in CINs (certainly
> if you use correct values of arguments). However arrays are passed to
> CIN via handles and if you want to manipulate with sizes of these
> arrays you should use SetCINArraySize or NumericArrayResize routines.
>
> If you could send a small C code illustrating the trouble, I would
have
> more possibilities to help you.
>
> Regards,
> Kostya.
>
> In article <8lqarr$855$1@nnrp1.deja.com>,
> eugenekim@my-deja.com wrote:
> > hello
> >
> > i'm having trouble with arrays, pointers, and releasing them in
CINs..
> First
> > off, i'm following the example in the Code Interface Reference
Manual
> 2-18
> > (pg 70). In this example, they manipulate arrays by having a
pointer
> point
> > to the first element of the array that the handle it pointing to:
> float32
> > *aElmtp; aElmtp = (*ah) -> arg1; (where ah is the name of the handle
> of the
> > array being passed into a CIN)
> >
> > I did this and it seemed to work for a while but then i kept on
> getting
> > Application errors in windows NT. It said that it couldn't write to
> a memory
> > space that it was referencing. Later on, i saw on 5-10 pg 121
> of the same
> > manual that DSNewPtr would help out if there were memory problems..
> this
> > works fine except now the program crashes whenever i try to use
> DSDisposePtr
> > to release the pointers.. and if i don't use it, the program crashes
> every so
> > often because the memory gets full.. I'm passing in 3 arrays into
the
> CIN and
> > therefore creating and trying to dispose of 3 pointers. i debugged
> the CIN
> > and it crashed every time at the DSDisposePtr. can anyone help? i
am
> using
> > Labview 5.1.1 in Windows NT. Thank you for your input.
> >
> > Eugene Kim
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 4 of 6
(3,207 Views)
> the exact bit of code was:
>
> int32 *Analogs;
> Analogs = (int32 *)DSNewPtr(sizeof(int32));
> Analogs = (*var1)->_0_V_Power_Supply_VDC_;
> /*
> .
> array operations
> .
> */
> DSDisposePtr(Analogs);
>
> when i debugged the CIN using DebugBreak, it always crashed at the
> DSDisposePtr(Analogs);. i guess that's because i was trying to delete
> (*var1)->_0_V_Power_Supply_VDC_ instead of the pointer Analogs? my
> program seems stable if i get rid of the DSDisposePtr... but is this ok?
> do i even need the DSNewPtr? if i leave this around will it end up
> leaking a whole lot of memory or will NT be able to clean it up after LV
> is closed?
>


Notice that Analogs first holds
the pointer returned from an allocation function.
That value is never used, and in the next statement, it is reassigned to point
to something that you did not allocate. That is why the Dispose fails, because
Analogs is no longer a pointer to an allocated buffer, but to something that
you shouldn't be deleting. There is already a memory leak, and a crash.
If
you comment out or delete the Dispose, then you are left with the leak. Delete
the DSNewPtr and the value of Analogs is no different for all of the array
operations.

Greg McKaskle
0 Kudos
Message 5 of 6
(3,203 Views)
Ok, i think i understand now. Thanks a lot for your help!

Eugene

In article <3982353F.8B8083C3@austin.rr.com>,
gmckaskle@austin.rr.com wrote:
> > the exact bit of code was:
> >
> > int32 *Analogs;
> > Analogs = (int32 *)DSNewPtr(sizeof(int32));
> > Analogs = (*var1)->_0_V_Power_Supply_VDC_;
> > /*
> > .
> > array operations
> > .
> > */
> > DSDisposePtr(Analogs);
> >
> > when i debugged the CIN using DebugBreak, it always crashed at the
> > DSDisposePtr(Analogs);. i guess that's because i was trying to
delete
> > (*var1)->_0_V_Power_Supply_VDC_ instead of the pointer Analogs? my
> > program seems stable if i get rid of the DSDisposePtr... but is
this ok
?
> > do i even need the DSNewPtr? if i leave this around will it end up
> > leaking a whole lot of memory or will NT be able to clean it up
after LV
> > is closed?
> >
>
> Notice that Analogs first holds the pointer returned from an
allocation function.
> That value is never used, and in the next statement, it is reassigned
to point
> to something that you did not allocate. That is why the Dispose
fails, because
> Analogs is no longer a pointer to an allocated buffer, but to
something that
> you shouldn't be deleting. There is already a memory leak, and a
crash.
> If
> you comment out or delete the Dispose, then you are left with the
leak. Delete
> the DSNewPtr and the value of Analogs is no different for all of the
array
> operations.
>
> Greg McKaskle
>


Sent via Deja.com http://www.deja.com/
Before you buy.
0 Kudos
Message 6 of 6
(3,203 Views)