Skip to content

Commit c6b9b47

Browse files
authored
Update C++-online-2025-external-polymorphism-and-type-erasure.md
1 parent d50d8fa commit c6b9b47

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

presentations/C++-online-2025-external-polymorphism-and-type-erasure.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,19 +358,23 @@ Even O'Dwyer's article merely hints at some ice in the distance, there's a mount
358358

359359
There are plenty more things to think about: What about using memory pools for allocation? what if at the same time we get polymorphism we get more sophisticated semantics such as "copy on write"? It turns out all of this is possible!
360360

361+
Also notice that any new powers with regards to Type Erasure in `zoo::AnyContainer` framework directly benefits `zoo::Function`, for no extra effort, for no performance loss!
362+
363+
`zoo::Function` adds one function call signature. But this is not limitative, both `zoo::AnyContainer` and `zoo::Function` can be refined, infinitely, by a "policy" builder that takes something that provides type erasure in the style of `zoo::AnyContainer` and adds even more user specified polymorphic interfaces. To show you how this is done is outside of the scope of this document; but, in principle, this could be just one mechanism to give more call interfaces to the equivalent of `std::function`. There are others!
364+
361365
### Why Type Erasure is "Internal External Polymorphism"
362366

363367
Think about it: as long as we satisfy the actual polymorphic interface that the user specifies, a type-erasure container might not even maintain objects of the type given; it can transform them underneath to whatever it wants, again, as long as the user-specified capabilities are respected!
364368

365369
In EP, the design pattern had to use the objects in their original types, because the objects are external to it (it's in the name).
366370

367-
Type Erasure does not have that restriction: It has 'internalized' what it is giving "external polymorphism" to. Because this is internal, and the only visibility to the outside world is the polymorphic interface, Type Erasure can represent the values it handles in whichever way it wants!
371+
Type Erasure does not have that restriction: It has 'internalized' what it is giving "external polymorphism" to. Because this is internal, and the only things visible to the outside world are the polymorphic interfaces, Type Erasure can represent the values it handles in whichever way it wants!
368372

369373
I've never seen any of these powers unlocked. I'm beginning to take advantage of this, "stay tuned".
370374

371375
### Value Manager
372376

373-
In my opinion, these errors and missed opportunities have happened because we have a totally not-articulated concept of generalized ownership, that I call the Generic Programming concept of "Value Manager".
377+
In my opinion, these errors and missed opportunities have happened because we, in the community, have a totally not-articulated concept of generalized ownership, that I call the Generic Programming concept of "Value Manager".
374378

375379
It turns out that "Value Management" is a concept that appears, as its name indicates, at every single place where value management happens. Take for example `std::optional`. `std::optional`, by itself, won't need to allocate: it can simply make its internal buffer suitable to host a value of what it is optional of. But what if the `std::optional` may contain a `std::vector<ComplicatedType>`?
376380

@@ -380,12 +384,14 @@ It turns out this is very important for an organization as large as Bloomberg: t
380384

381385
And their solution only applies to the value management concern of allocation.
382386

383-
In the experimental work I've done at `AnyContainer` value management, I've already been able to implement things like "reference counting", "copy on write", memory pools (a generalizaton of allocators). It is clear that the concept of value management applies to all containers in C++.
387+
The code in `zoo::AnyContainer` refers to value management in identifiers and comments, the names of `ByValue` and `ByReference` are supposed to abbreviate `ManagementByValue` and `ManagementByReference`, and this makes clear that there could be other managers. But these mechanisms belong to the 2nd generation of the framework. These managers are reifications of a more abstract concept of "manager", which in the first generation I named as `Container`. The identification/articulation of Value Manager happened gradually while devising the 2nd. Generation of the framework.
384388

385389
Why did I discover/identified this? because of the approach grounded on superior principles: Looking at Type Erasure as EP + Ownership, primed me to deeply inspect the world of possibilities concerning ownership, and the question of how to express them.
386390

391+
In the experimental work I've done at `AnyContainer` value management, I've already been able to implement things like "reference counting", "copy on write", memory pools (a generalizaton of allocators). I've been redesigning the `zoo` type erasure framework to allow very radical ways of Value Management possible, I'd say that I am about at generation "2.5", and I'm proceeding slowly because I'm dealing with concepts, ideas, that I have never heard about before. For example, it is clear that the concept of value management applies to all containers in C++; while at Bloomberg they are solving for just the value management concern of allocation, I'm working on a framework for generalized value management concerns, in which metaprogramming is essential.
392+
387393
## Unexplored possibilities
388394

389-
I am very interested in "Data Orientation", which requires the conversion of "collections of structs" to "structs of arrays". Maintaining the "scattered" representation of objects (as an structure of arrays with the fields) is quite effort intensive, so, we need to invent or devise the ways to provide this support in abstract, and general ways.
395+
I am very interested in "Data Orientation", which requires the conversion of "collections of structs" to "structs of arrays of homogenous data". Maintaining the "scattered" representation of objects (as an structure of arrays with the fields) is quite effort intensive, so, we need to invent or devise the ways to provide this support in abstract, and general ways.
390396

391-
I am beginning to speculate now, but perhaps those abstract ways are a natural occasion to apply runtime polymorphism, scattering requires changing the runtime, and this can be seen as a polymorphic interface for types that are not aware that they are "scattered". Through Type Erasure we are not forced to keep the objects in their original representation, we have the freedom to "scatter" them into "structs of arrays". The early work in this direction is promising. Organizing the data of applications in ways that you can get the full benefits of Data Orientation could be in the order of over 10x improvement; there is a very big prize for this endeavor.
397+
I am beginning to speculate now, but perhaps those abstract ways are a natural occasion to apply runtime polymorphism, scattering requires changing the runtime, and this can be seen as a polymorphic interface for types that are not aware that they are "scattered" inside Type Erasure. Through Type Erasure we are not forced to keep the objects in their original representation, we have the freedom to "scatter" them into "structs of arrays". The early work in this direction is promising. Organizing the data of applications in ways that you can get the full benefits of Data Orientation could be in the order of over 10x improvement; there is a very big prize for this endeavor.

0 commit comments

Comments
 (0)