GithubHelp home page GithubHelp logo

align's People

Contributors

eldiener avatar ericonr avatar gielvanschijndel-tomtom avatar glenfe avatar grafikrobot avatar jfalcou avatar lastique avatar mike-devel avatar pdimov avatar timblechmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

align's Issues

Provide align_up/align_down for arbitrary integers

It is sometimes useful to align integers other than size_t to a certain boundary. Using size_t regardless of the user's integer type is not possible if the type is larger than size_t (which is difficult to know portably given that size_t is platform-dependent).

align: overflow in overflow check

This code:

#include <boost/align/align.hpp>

int main()
{
  auto ptr ((void*)140665412970093);
  std::size_t space (211);

  if (boost::alignment::align (1024, 195, ptr, space) != nullptr)
  {
    std::abort();
  }
}

aborts when compiled using -DBOOST_NO_CXX11_STD_ALIGN.

This diff

diff --git a/include/boost/align/detail/align.hpp b/include/boost/align/detail/align.hpp
index 905940a..0483c55 100644
--- a/include/boost/align/detail/align.hpp
+++ b/include/boost/align/detail/align.hpp
@@ -22,8 +22,9 @@ align(std::size_t alignment, std::size_t size, void*& ptr,
     if (size <= space) {
         char* p = reinterpret_cast<char*>(~(alignment - 1) &
             (reinterpret_cast<std::size_t>(ptr) + alignment - 1));
-        std::size_t n = space - (p - static_cast<char*>(ptr));
-        if (size <= n) {
+        std::size_t d = p - static_cast<char*>(ptr);
+        std::size_t n = space - d;
+        if (d <= space && size <= n) {
             ptr = p;
             space = n;
             return p;

deals with the case that the pointer after alignment is already outside the available space.

aligned_allocator not working with MSVC2017 std::allocate_shared

Reproduction on Compiler Explorer: https://gcc.godbolt.org/z/kJuafk

#include <boost/align/aligned_allocator.hpp>
#include <type_traits>

struct alignas(64) C
{};

template<typename T>
using Allocator = boost::alignment::aligned_allocator<T, std::alignment_of_v<T>>;

auto f()
{
      auto a = Allocator<C>{};
      return std::allocate_shared<C>(a);
}

Error: error C2139: 'std::_Wrap_alloc<boost::alignment::aligned_allocator<U,64>>': an undefined class is not allowed as an argument to compiler intrinsic type trait '__is_empty'

User customization for aligned_alloc and aligned_free

Users have needs such as being able to customize which allocation function aligned_alloc uses. Currently it detects the best available option on the given implementation and provides a fallback implementation which uses std::malloc in combination with std::align. We will do all of the following:

  • Allow users to pick a specific implementation via a macro
  • Provide an additional implementation where alignment-aware operator new is available
  • Allow users to choose which fallback allocation function is used (e.g. instead of std::malloc(std::size_t) users could choose to have ::operator new(std::size_t, const std::nothrow_t&)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.