int8(), int16()… all return the same shared_ptr<DataType> that gets inc-ref’d on every "creation".
But any code taking type pointers shouldn't assume it comes from `static` storage. All uses of a non-owning TypeHolder should be based on something else ensuring the shared_ptr is alive while the TypeHolder is used. __ Felipe On Tue, 4 Jul 2023 at 11:20 wish maple <maplewish...@gmail.com> wrote: > Hi, > > By looking into the code of arrow compute, I found there it uses > `TypeHolder` [1], and expression might call `GetTypes` to get the input or > output types. The document for `TypeHolder` says that it's a container for > dynamically created `shared_ptr<DataType>`. However, my view is: > > 1. It's widely used, and might store non-owned types(e.g [2]) > 2. There are some type factory for lots of data type, like [3], so > non-nested types tent to be used with singleton > > I wonder that when would `TypeHolder` has owned types, when would them have > non-owned types, and would some primitive types like int8, int16 or types > like string shares the same underlying pointer? > > Thanks, > Xuwei Fu > > > [1] https://github.com/apache/arrow/blob/main/cpp/src/arrow/type.h#L215 > [2] > > https://github.com/apache/arrow/blob/main/cpp/src/arrow/compute/expression_internal.h#L47 > [3] https://github.com/apache/arrow/blob/main/cpp/src/arrow/type.cc#L2510 >