понимание архитектуры OpenThread - PullRequest
0 голосов
/ 20 июля 2011

OpenThreads заявляет на своем веб-сайте:

It is of importance to note that while a factory pattern design could have 
been used to achieve the goal of genaric interface, it would have required 
the programmer to allocate each of the 4 fundemental types 
(Thread, Mutex, Barrier, & Condition ) on the heap.  Due 
to the cost associated with heap allocation of the underlying 
concrete implementations of these constructs on some platforms, 
such allocation was deemed unacceptable at the time this library 
was originally written, and thus the factory pattern was not used. 

Instead, a somewhat obtuse - but effective - technique was 
chosen to provide the necessary data/implementation hiding. 
This technique uses private void pointers to encapsulate object private data.  
The void pointers actually point at concrete data structures, 
but give a uniform interface to the dso.

Однако, глядя на реализацию, все эти частные указатели на void выделяются new.Например, в конструкторе барьера PThreads вызывается следующий код:

PThreadBarrierPrivateData *pd = new PThreadBarrierPrivateData();

Как можно избежать выделения кучи?

Кроме того, можно просто указать интерфейс в заголовочном файле и предоставитьнесколько реализаций (одна из которых была бы выбрана во время компиляции) были бы столь же эффективны для обеспечения сокрытия данных?

Я полагаю, что я что-то упускаю / не вижу всей картинки, поэтому любое просвещение будет оценено.

Приветствия

...