, sergej, Pimpl , Bridge.
C . , ++, , C ( pro - - C).
C
C struct, :
#ifndef FOO_H
#define FOO_H
struct Foo* foo_create(void);
void foo_destroy(struct Foo* foo);
void foo_do_something(struct Foo* foo);
#endif
#include "Foo.h"
struct Foo
{
};
struct Foo* foo_create(void)
{
return malloc(sizeof(struct Foo));
}
void foo_destroy(struct Foo* foo)
{
free(foo);
}
void foo_do_something(struct Foo* foo)
{
}
Pimpl, pro C. C private structs, struct . , , .
++ private, , , - Pimpl, C UDT class .
, , , , , , , :
[Opaque Pointer]-------------------------->[Internal Data Fields]
... , , , , - - .
, . , .
, , , ( C, , ++, , ). , , , , ( ) /.
, Java, ( ).
:
( ) , , O (1), . , Foos, , , Foo () ( ).
:
, , , , Foo ( Foo) Foo . , , , , Foo .
(, , ) Pimpl, . , , . , , , . , , - , ( , ) .
" , ! ! choppa!" - , - .
, class struct . .
Foo , , . , , Foo , Bar.h. , Foo.h Bar.h ( Foo.cpp ). Bar.h , , , , Pimpl.
, Pimpls , . , . , .
, Foo, . Foo.cpp, , Foo, -, . , (, ) , PITA.
, . >
, , , ..
API ABI
pro ( API) - API ( , ), . , class struct , , , , ABI. :
[Plugin Developer]----------------->[Internal Data Fields]
, - , ABI , . : , , , , , ABI.
(Pimpl) , ABI.
[Plugin Developer]----->[Opaque Pointer]----->[Internal Data Fields]
... , , .
, , :
:
- .
- . (, , ), .
- , / ( , , , , ).
- ABI, , ABI.
:
TL; DR
, , , C.