Debian Codegraph @

src/lib/core/t1/OJPH/others/ojph_mem.cpp

raw
1 //***************************************************************************/
2 // This software is released under the 2-Clause BSD license, included
3 // below.
4 //
5 // Copyright (c) 2019, Aous Naman
6 // Copyright (c) 2019, Kakadu Software Pty Ltd, Australia
7 // Copyright (c) 2019, The University of New South Wales, Australia
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 //
13 // 1. Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // 2. Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
26 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 //***************************************************************************/
32 // This file is part of the OpenJPH software implementation.
33 // File: ojph_mem.cpp
34 // Author: Aous Naman
35 // Date: 28 August 2019
36 //***************************************************************************/
37
38
39 #include <new>
40 #ifndef _MSC_VER
41 #pragma GCC diagnostic push
42 #pragma GCC diagnostic ignored "-Wconversion"
43 #pragma GCC diagnostic ignored "-Wsign-conversion"
44 #pragma GCC diagnostic ignored "-Wunused-parameter"
45 #pragma GCC diagnostic ignored "-Wunused-variable"
46 #pragma GCC diagnostic ignored "-Wsign-compare"
47 #pragma GCC diagnostic ignored "-Wparentheses"
48 #endif
49
50 #include "ojph_mem.h"
51
52 #ifndef _MSC_VER
53 #pragma GCC diagnostic pop
54 #endif
55
56 namespace ojph {
57
58 ////////////////////////////////////////////////////////////////////////////
59 //
60 //
61 //
62 //
63 //
64 ////////////////////////////////////////////////////////////////////////////
65
66 ////////////////////////////////////////////////////////////////////////////
67 template<>
68 void line_buf::finalize_alloc<si32>(mem_fixed_allocator *p)
69 {
70 assert(p != 0 && size != 0);
71 i32 = p->post_alloc_data<si32>(size, pre_size);
72 }
73
74 ////////////////////////////////////////////////////////////////////////////
75 template<>
76 void line_buf::finalize_alloc<float>(mem_fixed_allocator *p)
77 {
78 assert(p != 0 && size != 0);
79 f32 = p->post_alloc_data<float>(size, pre_size);
80 }
81
82 ////////////////////////////////////////////////////////////////////////////
83 template<>
84 void line_buf::wrap(si32 *buffer, size_t num_ele, ui32 pre_size)
85 {
86 i32 = buffer;
87 this->size = num_ele;
88 this->pre_size = pre_size;
89 }
90
91 ////////////////////////////////////////////////////////////////////////////
92 template<>
93 void line_buf::wrap(float *buffer, size_t num_ele, ui32 pre_size)
94 {
95 f32 = buffer;
96 this->size = num_ele;
97 this->pre_size = pre_size;
98 }
99
100 ////////////////////////////////////////////////////////////////////////////
101 //
102 //
103 //
104 //
105 //
106 ////////////////////////////////////////////////////////////////////////////
107
108 ////////////////////////////////////////////////////////////////////////////
109 void mem_elastic_allocator::get_buffer(ui32 needed_bytes, coded_lists* &p)
110 {
111 ui32 extended_bytes = needed_bytes + (ui32)sizeof(coded_lists);
112
113 if (store == NULL)
114 {
115 ui32 bytes = ojph_max(extended_bytes, chunk_size);
116 store = (stores_list*)malloc(bytes);
117 cur_store = store = new (store) stores_list(bytes);
118 total_allocated += bytes;
119 }
120
121 if (cur_store->available < extended_bytes)
122 {
123 ui32 bytes = ojph_max(extended_bytes, chunk_size);
124 cur_store->next_store = (stores_list*)malloc(bytes);
125 cur_store = new (cur_store->next_store) stores_list(bytes);
126 total_allocated += bytes;
127 }
128
129 p = new (cur_store->data) coded_lists(needed_bytes);
130
131 cur_store->available -= extended_bytes;
132 cur_store->data += extended_bytes;
133 }
134
135 }