X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fe2-interface.git;a=blobdiff_plain;f=e2sim%2Fprevious%2Fe2apv1sim%2Fe2sim%2Fsrc%2FASN1%2Fasn%2Fchunked_allocator.hpp;fp=e2sim%2Fprevious%2Fe2apv1sim%2Fe2sim%2Fsrc%2FASN1%2Fasn%2Fchunked_allocator.hpp;h=0000000000000000000000000000000000000000;hp=008be98f4ca1edabefae2950f343f97780f1fc23;hb=f86662b5b6481f27e18313a36355871f3a947193;hpb=a9f02a2b5886990fd81e64f7c218c5d4844f18a3 diff --git a/e2sim/previous/e2apv1sim/e2sim/src/ASN1/asn/chunked_allocator.hpp b/e2sim/previous/e2apv1sim/e2sim/src/ASN1/asn/chunked_allocator.hpp deleted file mode 100755 index 008be98..0000000 --- a/e2sim/previous/e2apv1sim/e2sim/src/ASN1/asn/chunked_allocator.hpp +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -/******************************************************************************* -* -* Copyright (c) 2019 AT&T Intellectual Property. -* Copyright (c) 2018-2019 Nokia. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*******************************************************************************/ - -// Standard Includes: ANSI C/C++, MSA, and Third-Party Libraries -#include -#include //std::bad_alloc -#include -#include - -// Platform Includes: Platform specific classes, functions, and libraries - -// Local Includes: Application specific classes, functions, and libraries - -namespace asn { - -template -class chunked_allocator -{ -public: - using allocator_t = ALLOC; - - chunked_allocator() - { - put_chunk(new_chunk()); - } - - template - decltype(auto) emplace_back(TSEQ& v) - { - try - { - return v.emplace_back(m_allocator); - } - catch (std::bad_alloc const&) - { - put_chunk(new_chunk()); - return v.emplace_back(m_allocator); - } - } - - uint8_t* alloc_bytes(std::size_t sz) - { - //TODO: unify allocation: now it returns nullptr instead of throw! - auto* ret = m_allocator.alloc_bytes(sz); - if (!ret) - { - put_chunk(new_chunk()); - ret = m_allocator.alloc_bytes(sz); - } - return ret; - } - -private: - static constexpr std::size_t CHUNK_SIZE = 32*1024; - using chunk_t = std::array; - using chunks_t = std::list; - - chunk_t& new_chunk() { return m_chunks.emplace_back(); } - void put_chunk(chunk_t& c) { m_allocator.reset(c.data(), c.size()); } - - - allocator_t m_allocator; - chunks_t m_chunks; -}; - -} //end: namespace asn