Skip to content

Instantly share code, notes, and snippets.

@lambday
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambday/8996223 to your computer and use it in GitHub Desktop.
Save lambday/8996223 to your computer and use it in GitHub Desktop.
#include <shogun/base/init.h>
#include <shogun/base/Parameter.h>
#include <shogun/lib/common.h>
#include <shogun/base/SGObject.h>
#include <shogun/io/SGIO.h>
#include <shogun/mathematics/Statistics.h>
using namespace shogun;
int main(int argc, char **argv)
{
init_shogun_with_defaults();
sg_io->set_loglevel(MSG_DEBUG);
index_t length1=2, length2=length1;
CStatistics** data1=new CStatistics*[length1];
for (index_t i=0; i<length1; ++i)
data1[i]=new CStatistics();
CStatistics** data2=NULL;
Parameter* source=new Parameter();
Parameter* target=new Parameter();
source->add_vector((CSGObject***)&data1, &length1, "data", "data");
target->add_vector((CSGObject***)&data2, &length2, "data", "data");
source->get_parameter(0)->copy(target->get_parameter(0));
delete source;
delete target;
for (index_t i=0; i<length1; ++i)
delete data1[i];
delete data1;
for (index_t i=0; i<length2; ++i)
delete data2[i];
delete data2;
exit_shogun();
return 0;
}
#include <shogun/base/init.h>
#include <shogun/base/Parameter.h>
#include <shogun/lib/common.h>
#include <shogun/base/SGObject.h>
#include <shogun/io/SGIO.h>
#include <shogun/mathematics/Statistics.h>
using namespace shogun;
int main(int argc, char **argv)
{
init_shogun_with_defaults();
sg_io->set_loglevel(MSG_DEBUG);
index_t length1=2, length2=length1;
CStatistics** data1=new CStatistics*[length1];
for (index_t i=0; i<length1; ++i)
data1[i]=new CStatistics();
CStatistics** data2=new CStatistics*[length1];
Parameter* source=new Parameter();
Parameter* target=new Parameter();
source->add_vector((CSGObject***)&data1, &length1, "data", "data");
target->add_vector((CSGObject***)&data2, &length2, "data", "data");
source->get_parameter(0)->copy(target->get_parameter(0));
delete source;
delete target;
for (index_t i=0; i<length1; ++i)
delete data1[i];
delete data1;
for (index_t i=0; i<length2; ++i)
delete data2[i];
delete data2;
exit_shogun();
return 0;
}
#include <shogun/base/init.h>
#include <shogun/base/Parameter.h>
#include <shogun/lib/common.h>
#include <shogun/base/SGObject.h>
#include <shogun/io/SGIO.h>
#include <shogun/mathematics/Statistics.h>
using namespace shogun;
int main(int argc, char **argv)
{
init_shogun_with_defaults();
sg_io->set_loglevel(MSG_DEBUG);
index_t length1=2, length2=length1;
CStatistics** data1=new CStatistics*[length1];
for (index_t i=0; i<length1; ++i)
data1[i]=new CStatistics();
CStatistics** data2=new CStatistics*[length1]();
Parameter* source=new Parameter();
Parameter* target=new Parameter();
source->add_vector((CSGObject***)&data1, &length1, "data", "data");
target->add_vector((CSGObject***)&data2, &length2, "data", "data");
source->get_parameter(0)->copy(target->get_parameter(0));
delete source;
delete target;
for (index_t i=0; i<length1; ++i)
delete data1[i];
delete data1;
for (index_t i=0; i<length2; ++i)
delete data2[i];
delete data2;
exit_shogun();
return 0;
}
==30458== Memcheck, a memory error detector
==30458== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==30458== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==30458== Command: ./a.out
==30458==
[DEBUG] entering TParameter::copy()
[DEBUG] Comparing datatypes without length
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] CT_VECTOR or CT_SGVECTOR
[DEBUG] entering TSGDataType::equals()
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] leaving TSGDataType::equals(): datatypes are equal
[DEBUG] allocating 16 bytes memory for target vector
[DEBUG] entering TSGDataType::equals()
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] leaving TSGDataType::equals(): datatypes are equal
[DEBUG] length_y: 2
[DEBUG] copying element 0 which is 0 byes from start
[DEBUG] entering TParameter::copy_stype()
[DEBUG] ST_NONE
[DEBUG] entering TParameter::copy_ptype()
==30458== Conditional jump or move depends on uninitialised value(s)
==30458== at 0x4FF8254: shogun::TParameter::copy_ptype(shogun::EPrimitiveType, void*, void*) (Parameter.cpp:3656)
==30458== by 0x4FFA1FB: shogun::TParameter::copy(shogun::TParameter*) (Parameter.cpp:4041)
==30458== by 0x401720: main (clone_bug.cpp:24)
==30458== Uninitialised value was created by a heap allocation
==30458== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==30458== by 0x5494F80: shogun::sg_malloc(unsigned long) (memory.cpp:204)
==30458== by 0x4FFA4CE: shogun::TParameter::copy(shogun::TParameter*) (memory.h:80)
==30458== by 0x401720: main (clone_bug.cpp:24)
==30458==
[DEBUG] entering Statistics::clone()
[DEBUG] constructing an empty instance of Statistics
[DEBUG] leaving Statistics::clone(): Clone successful
[DEBUG] leaving TParameter::copy_ptype(): Copy successful
[DEBUG] copying element 1 which is 8 byes from start
[DEBUG] entering TParameter::copy_stype()
[DEBUG] ST_NONE
[DEBUG] entering TParameter::copy_ptype()
[DEBUG] entering Statistics::clone()
[DEBUG] constructing an empty instance of Statistics
[DEBUG] leaving Statistics::clone(): Clone successful
[DEBUG] leaving TParameter::copy_ptype(): Copy successful
[DEBUG] leaving TParameter::copy(): Copy successful
==30458==
==30458== HEAP SUMMARY:
==30458== in use at exit: 0 bytes in 0 blocks
==30458== total heap usage: 256 allocs, 256 frees, 49,106 bytes allocated
==30458==
==30458== All heap blocks were freed -- no leaks are possible
==30458==
==30458== For counts of detected and suppressed errors, rerun with: -v
==30458== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 2 from 2)
==30531== Memcheck, a memory error detector
==30531== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==30531== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==30531== Command: ./a.out
==30531==
[DEBUG] entering TParameter::copy()
[DEBUG] Comparing datatypes without length
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] CT_VECTOR or CT_SGVECTOR
[DEBUG] entering TSGDataType::equals()
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] leaving TSGDataType::equals(): datatypes are equal
[DEBUG] entering TSGDataType::equals()
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] leaving TSGDataType::equals(): datatypes are equal
[DEBUG] length_y: 2
[DEBUG] copying element 0 which is 0 byes from start
[DEBUG] entering TParameter::copy_stype()
[DEBUG] ST_NONE
[DEBUG] entering TParameter::copy_ptype()
==30531== Conditional jump or move depends on uninitialised value(s)
==30531== at 0x4FF8254: shogun::TParameter::copy_ptype(shogun::EPrimitiveType, void*, void*) (Parameter.cpp:3656)
==30531== by 0x4FFA1FB: shogun::TParameter::copy(shogun::TParameter*) (Parameter.cpp:4041)
==30531== by 0x401745: main (clone_bug.cpp:24)
==30531== Uninitialised value was created by a heap allocation
==30531== at 0x4A0645D: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==30531== by 0x5494EC0: operator new[](unsigned long) (memory.cpp:152)
==30531== by 0x4016A1: main (clone_bug.cpp:19)
==30531==
[DEBUG] entering Statistics::clone()
[DEBUG] constructing an empty instance of Statistics
[DEBUG] leaving Statistics::clone(): Clone successful
[DEBUG] leaving TParameter::copy_ptype(): Copy successful
[DEBUG] copying element 1 which is 8 byes from start
[DEBUG] entering TParameter::copy_stype()
[DEBUG] ST_NONE
[DEBUG] entering TParameter::copy_ptype()
[DEBUG] entering Statistics::clone()
[DEBUG] constructing an empty instance of Statistics
[DEBUG] leaving Statistics::clone(): Clone successful
[DEBUG] leaving TParameter::copy_ptype(): Copy successful
[DEBUG] leaving TParameter::copy(): Copy successful
==30531==
==30531== HEAP SUMMARY:
==30531== in use at exit: 0 bytes in 0 blocks
==30531== total heap usage: 256 allocs, 256 frees, 49,106 bytes allocated
==30531==
==30531== All heap blocks were freed -- no leaks are possible
==30531==
==30531== For counts of detected and suppressed errors, rerun with: -v
==30531== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 2 from 2)
==30586== Memcheck, a memory error detector
==30586== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==30586== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==30586== Command: ./a.out
==30586==
[DEBUG] entering TParameter::copy()
[DEBUG] Comparing datatypes without length
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] CT_VECTOR or CT_SGVECTOR
[DEBUG] entering TSGDataType::equals()
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] leaving TSGDataType::equals(): datatypes are equal
[DEBUG] entering TSGDataType::equals()
[DEBUG] leaving TSGDataType::equals_without_length(): data types without lengths are equal
[DEBUG] leaving TSGDataType::equals(): datatypes are equal
[DEBUG] length_y: 2
[DEBUG] copying element 0 which is 0 byes from start
[DEBUG] entering TParameter::copy_stype()
[DEBUG] ST_NONE
[DEBUG] entering TParameter::copy_ptype()
[DEBUG] entering Statistics::clone()
[DEBUG] constructing an empty instance of Statistics
[DEBUG] leaving Statistics::clone(): Clone successful
[DEBUG] leaving TParameter::copy_ptype(): Copy successful
[DEBUG] copying element 1 which is 8 byes from start
[DEBUG] entering TParameter::copy_stype()
[DEBUG] ST_NONE
[DEBUG] entering TParameter::copy_ptype()
[DEBUG] entering Statistics::clone()
[DEBUG] constructing an empty instance of Statistics
[DEBUG] leaving Statistics::clone(): Clone successful
[DEBUG] leaving TParameter::copy_ptype(): Copy successful
[DEBUG] leaving TParameter::copy(): Copy successful
==30586==
==30586== HEAP SUMMARY:
==30586== in use at exit: 0 bytes in 0 blocks
==30586== total heap usage: 256 allocs, 256 frees, 49,106 bytes allocated
==30586==
==30586== All heap blocks were freed -- no leaks are possible
==30586==
==30586== For counts of detected and suppressed errors, rerun with: -v
==30586== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment