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

Non-trivial data sources #24

Open
psiha opened this issue May 10, 2022 · 3 comments
Open

Non-trivial data sources #24

psiha opened this issue May 10, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@psiha
Copy link
Contributor

psiha commented May 10, 2022

Can you make your allocator machinery support allocators (e.g. auto defragmenting allocators) that return handles - objects that contain pointers which can be changed under-the-hood so you cannot store the pointer but rather have to ask the handle for the pointer (call get() or data() on it) every time you need the pointer to the data (it is up to the user to make sure and pin the handle or allocator when data access is required)?

Similarily for the detail::view_builder<>::data_block machinery - can it support data sources that are:

  • handles (i.e. one extra level of indirection)
  • CRTP derived classes (i.e. the view does not store the source object but casts itself to it - that is the way I 'handle the handle' pardon the pun :D)
template < typename DimensionsParam, typename DataSource >
struct ViewImpl : private DimensionsParam
{
    using Dimensions = DimensionsParam;

    constexpr ViewImpl() noexcept = default;
    constexpr ViewImpl( Dimensions const & dimensions ) noexcept { this->setDimensions( dimensions ); }

    constexpr auto count() const noexcept { return this->dimensions().count(); }

    constexpr auto dimension( std::uint8_t const index ) const noexcept { return this->dimensions()[ index ]; }
    constexpr auto shape    ( std::uint8_t const index ) const noexcept { return dimension( index ); }

    template < typename ... Indices > auto const & operator()( Indices ... indices ) const noexcept { return const_cast< ViewImpl & >( *this ).operator()( indices... ); }
    template < typename ... Indices > auto       & operator()( Indices ... indices )       noexcept { return getData()[ this->dimensions().index( indices... ) ]; }

    ....

private:
    BOOST_FORCEINLINE auto getData()       noexcept { return static_cast< DataSource * >( this )->data(); }
    BOOST_FORCEINLINE auto getData() const noexcept { return const_cast< ViewImpl & >( *this ).getData(); }

protected:
    constexpr void setDimensions( Dimensions const & newDimensions ) noexcept { static_cast< Dimensions & >( *this ) = newDimensions; }
}; // struct ViewImpl

(might be related to #7 WRT storing 'non trivial pointers' in views)

@psiha psiha added the enhancement New feature or request label May 10, 2022
@jfalcou
Copy link
Owner

jfalcou commented May 10, 2022

This is the next version of data_block: https://github.com/jfalcou/kiwaku/blob/feature/table/include/kwk/container/components/data_block.hpp

I think the handle situation can just be made so the pointer/reference types can be deferred to Source instead of computed via traits.
data() access is fully in the control of the Source type and nothing ask for it to be an actual pointer, just somethign with a [] on it. So I think it's not much to do.

As for the pointer not being stored bug asked every time, that's what source data() does, so we can probably just make a block that do w/e in data(). If you have a concrete example I can make a test and check it works

@jfalcou
Copy link
Owner

jfalcou commented May 10, 2022

Well, the heap_block class in the feature/table branch just does that: it contains an unique_ptr and uses data() to do the get() so I think it just works.

@psiha
Copy link
Contributor Author

psiha commented Mar 14, 2023

lol - we already discussed this almost a year ago :D

so repeat the live discussion:

  • i'd need a 'viewy thingy' - that might be your 'container' - that would 'crtp-like' delegate the data pointer getting - i guess you'd have to expand your 'source' machinery to support that
  • way to explicitly define a view type (so that it can for example be derived from)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants