VirtualBox

source: vbox/trunk/include/iprt/nocrt/memory@ 96354

Last change on this file since 96354 was 95993, checked in by vboxsync, 2 years ago

include/iprt/nocrt: More on ostream, limits. Stubbed std::sort. bugref:10261

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/** @file
2 * IPRT / No-CRT - Minimal C++ std::memory.
3 */
4
5/*
6 * Copyright (C) 2022 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_nocrt_memory
27#define IPRT_INCLUDED_nocrt_memory
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/nocrt/cstddef>
33#include <iprt/nocrt/new>
34
35namespace std
36{
37 /**
38 * Simple allocator - not C++11 compliant.
39 */
40 template<class a_Type> class allocator
41 {
42 public:
43 typedef a_Type value_type;
44 typedef a_Type const &const_reference;
45 typedef a_Type *pointer;
46 typedef a_Type const *const_pointer;
47 typedef std::size_t size_type;
48 typedef std::ptrdiff_t difference_type;
49
50 public:
51 allocator() RT_NOEXCEPT
52 { }
53
54 allocator(allocator const &a_rThat) RT_NOEXCEPT
55 { RT_NOREF(a_rThat); }
56
57 ~allocator()
58 { }
59
60 a_Type *allocate(size_type a_cItems, const void *a_pvHint = NULL)
61 {
62 RT_NOREF(a_pvHint);
63 Assert(a_cItems <= max_size()); /** @todo throw stuff */
64 return static_cast<pointer>(::operator new(sizeof(value_type) * a_cItems));
65 }
66
67 void deallocate(a_Type *a_paItems, size_type a_cItems)
68 {
69 if (a_paItems && a_cItems > 0)
70 ::operator delete(a_paItems);
71 }
72
73 size_type max_size() const
74 {
75 /* whatever */
76#if ARCH_BITS >= 64
77 return _4G / sizeof(value_type);
78#else
79 return _512M / sizeof(value_type);
80#endif
81 }
82
83 void construct(pointer a_pDst, const_reference a_rSrc)
84 {
85 ::new (static_cast<void *>(a_pDst)) a_Type(a_rSrc);
86 }
87
88 void destroy(pointer a_pDst)
89 {
90 a_pDst->~value_type();
91 }
92 };
93
94 /** @todo make_unique and unique */
95}
96
97#endif /* !IPRT_INCLUDED_nocrt_memory */
98
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette