I got memory access violation when I use the destructor method. Is there any way to destroy a stream explicitly?
Stack objects are automatically destroyed at the end of their scope:
float fun1(float *v_data, float *size ) {
s_data1 = Stream<float > (2, size );
s_data1.load(v_data );
{
Stream<float> s_temp(2, size );
...
} // dispose s_temp
...
return val;
} // dispose s_data1
Heap objects are destroyed calling delete (only once) or automatically at the end of the program.
float fun2(float *v_data, float *size ) {
Stream<float> *s_data_ptr = new Stream<float > (2, size );
s_data_ptr-> load(v_data );
...
delete s_data_ptr; // dispose s_data_ptr
return val;
}
If you still get memory access violation I can paste a full example here, but probably it's related to memory corruption or pointer handling.
Is there no other way? I mean out of scope isn't too convenient or it it the only way ATM
Help anybody. Is there no other way?
Originally posted by: riza.guntur
Help anybody. Is there no other way?
Thank you very much.
When I read Ceq for a glance I didn't understand, I didn't see and didn't understand about stack and heap objects.
Anyway my problem has been finished using heap object as return value (or returning pointer, or whatever the type) with stack object destroyed at the end of scope such as one below.
Stream<float4> *input_to_fuzzy(float2 *input_array, unsigned int rank, unsigned int *input_stream_size, unsigned int *fuzzy_stream_size)
{
Stream<float2> input(rank, input_stream_size);//stream input training
Stream<float4> *fuzzy_number = new Stream<float4>(rank, fuzzy_stream_size);//x mean, y for max, z for min
input.read(input_array);
max_min_mean(input,*fuzzy_number);
return fuzzy_number;
}