The Wayback Machine - https://web.archive.org/web/20200528055155/https://github.com/nim-lang/Nim/issues/12726
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot take the compile-time sizeof Atomic types #12726

Open
mratsim opened this issue Nov 24, 2019 · 0 comments
Open

Cannot take the compile-time sizeof Atomic types #12726

mratsim opened this issue Nov 24, 2019 · 0 comments

Comments

@mratsim
Copy link
Collaborator

@mratsim mratsim commented Nov 24, 2019

sizeof doesn't work for types that store Atomics. This would be useful to size the memory buffer for thread-safe memory allocators with what is left from the synchronization primitives.

import std/atomics

type
  Node = ptr object
    # works
    next: Atomic[pointer]

  MyChannel = object
    # type not defined completely
    back: Atomic[ptr int]

static:
  echo sizeof(Node)
  echo sizeof(MyChannel)

The workaround is to add a "raw" field for all the trivial types with their actual types so that sizeof works.

There is a similar concern for Locks and Condition Variables though I don't think there is an easy way to make sizeof deduce their size.

mratsim added a commit to mratsim/weave that referenced this issue Nov 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.