# Structs with Fixed length strings and allocatedinline

**URL:** <https://discourse.julialang.org/t/structs-with-fixed-length-strings-and-allocatedinline/97646>\
**Category:** General Usage\
**Created:** [April 19, 2023, 11:07am UTC](https://discourse.julialang.org/t/structs-with-fixed-length-strings-and-allocatedinline/97646 "2023-04-19T11:07:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vinothkumar\_Raman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vinothkumar_raman/32/49117_2.png) [@Vinothkumar\_Raman](https://discourse.julialang.org/u/Vinothkumar_Raman)\
**Post date:** [April 19, 2023, 11:07am UTC](https://discourse.julialang.org/t/structs-with-fixed-length-strings-and-allocatedinline/97646/1 "2023-04-19T11:07:02Z")

</div>

I have struct like this,

```julia
struct A
        a:: Symbol
end

```

I see a huge number of allocations of objects `Union{A, Nothing}`. I checked

```julia
> Base.allocatedinline(A)
true
> Base.allocatedinline(Union{A, Nothing})
false

```

I originally wished it to be Symbol, because there are few of them possible and wanted equality to be faster.

I tried both `InlinedStrings.jl` and `StaticStrings.jl` libraries. Though the `allocatedinline` of the same with StaticString field (the union type) is true now, the equality has gone worse. My allocations have halved but it has slowed down tremendously. (InlinedStrings still says `allocatedinline` as false for the union type for some reason).

I am not sure how people generally avoid allocation of structs with string fields

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 19, 2023, 12:18pm UTC](https://discourse.julialang.org/t/structs-with-fixed-length-strings-and-allocatedinline/97646/2 "2023-04-19T12:18:30Z")

</div>

For me it seems a bit like the concrete usage could make a difference. Do you create a lot of these structs all the time, are you processing large arrays with such data… A minimal example could help to get relevant answers.

(My initial guess is that you might deal with some vector where the type is not fixed and the allocations stem from runtime dispatch rather then actual allocations of `Union{A, Nothing}`.)

* * *

I think it is important to differentiate between necessary allocations and allocations which cause a slow-down. Say, if you have one million strings of length 10, then it might be good to allocation one million strings in as few calls as possible, maybe even in a smart way. However, it would not make sense to do all of that in the heap or inline, as it is too much data.

That is why the use case could matter.
