[cffi-devel] How would i write the exact equivelant of a C New Operator
Brian Spilsbury
brian.spilsbury at gmail.com
Wed Oct 30 00:57:04 UTC 2013
http://docs.opencv.org/modules/core/doc/basic_structures.html
CvPoint2D32f is a C structure, so you should be able to replace new
CvPoint2D32f[ board_n ]; with malloc(sizeof (CvPoint2D32f) * board_n); but
new upon a struct type in C++ also initializes the contents to the
appropriate zero values, so you'll need to add code to do that yourself.
Test it in the example code, and see if you can compile and run it with a C
compiler.
Once you can do that, cffi should be straight-forward to use.
On Mon, Oct 28, 2013 at 5:15 PM, Joeish W <joeish80829 at yahoo.com> wrote:
> Im converting this code here
>
> int board_n = board_w * board_h;
> CvPoint2D32f* corners = new CvPoint2D32f[ board_n ];
>
> from this link http://dasl.mem.drexel.edu/~noahKuntz/openCVTut10.html
> and in the code is a new operator id like to convert but i could use
> guidance how.
> first of all i looked on google and there actually doesnt appear to be a
> C new operator only C++ which is a little weird because the code at the
> above link is full of only OpenCV C functions so either there is a C new
> operator or the author is using C and C++ together. I was going to do
> foreign-alloc but at this link<http://en.cppreference.com/w/cpp/memory/new/operator_new>about the new operator for C++ it says
> "Allocatescountbytes from free store. Calls the function pointer returned
> by std::get_new_handler<http://en.cppreference.com/w/cpp/memory/new/get_new_handler>on failure and repeats allocation attempts until new handler does not
> return or becomes a null pointer, at which time throws std::bad_alloc<http://en.cppreference.com/w/cpp/memory/new/bad_alloc>
> ."
>
> I dont really know what to make of that and that link is for C++...thus
> the reason for my question....any guidance is appreciated
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20131030/2f040a50/attachment.html>
More information about the cffi-devel
mailing list