mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
implemented rb_cvAlloc and replaced cvAlloc with rb_cvAlloc to allocate memory buffer as much as possible
This commit is contained in:
parent
196c567ee0
commit
586f2161eb
6 changed files with 94 additions and 29 deletions
|
@ -129,6 +129,35 @@ release_iplconvkernel_object(void *ptr)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocates a memory buffer
|
||||
* When memory allocation is failed, run GC and retry it
|
||||
*/
|
||||
void*
|
||||
rb_cvAlloc(size_t size)
|
||||
{
|
||||
void* ptr = NULL;
|
||||
try {
|
||||
ptr = cvAlloc(size);
|
||||
}
|
||||
catch(cv::Exception& e) {
|
||||
if (e.code != CV_StsNoMem)
|
||||
rb_raise(rb_eRuntimeError, "%s", e.what());
|
||||
|
||||
rb_gc_start();
|
||||
try {
|
||||
ptr = cvAlloc(size);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
if (e.code == CV_StsNoMem)
|
||||
rb_raise(rb_eNoMemError, "%s", e.what());
|
||||
else
|
||||
rb_raise(rb_eRuntimeError, "%s", e.what());
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates CvMat and underlying data
|
||||
* When memory allocation is failed, run GC and retry it
|
||||
|
@ -158,6 +187,35 @@ rb_cvCreateMat(int height, int width, int type)
|
|||
return ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create IplImage header and allocate underlying data
|
||||
* When memory allocation is failed, run GC and retry it
|
||||
*/
|
||||
IplImage*
|
||||
rb_cvCreateImage(CvSize size, int depth, int channels)
|
||||
{
|
||||
IplImage* ptr = NULL;
|
||||
try {
|
||||
ptr = cvCreateImage(size, depth, channels);
|
||||
}
|
||||
catch(cv::Exception& e) {
|
||||
if (e.code != CV_StsNoMem)
|
||||
rb_raise(rb_eRuntimeError, "%s", e.what());
|
||||
|
||||
rb_gc_start();
|
||||
try {
|
||||
ptr = cvCreateImage(size, depth, channels);
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
if (e.code == CV_StsNoMem)
|
||||
rb_raise(rb_eNoMemError, "%s", e.what());
|
||||
else
|
||||
rb_raise(rb_eRuntimeError, "%s", e.what());
|
||||
}
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
VALUE rb_module;
|
||||
VALUE rb_opencv_constants;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue