acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
typed_memory.h
1
// Created by camilo on 2022-10-23 03:10 <3ThomasBorregaardSorensen!!
2
#pragma once
3
4
5
#include "management.h"
6
7
8
namespace
heap
9
{
10
11
12
template
<
class
TYPE >
13
class
operating_system_typed_memory
14
{
15
public
:
16
17
inline ::heap::allocator* allocator() { return ::acme::get()->m_pheapmanagement->m_pallocator; }
18
19
20
inline
TYPE* allocate(::collection::count c, ::collection::count * pcAllocated, const_char_pointer pszFile, ::i32 iLine)
21
{
22
23
memsize sizeAllocated = 0;
24
25
auto
p = (TYPE*)allocator()->allocate(
sizeof
(TYPE) * c, &sizeAllocated);
26
27
if
(pcAllocated)
28
{
29
30
*pcAllocated = sizeAllocated /
sizeof
(TYPE);
31
32
}
33
34
return
p;
35
36
}
37
38
39
inline
TYPE* allocate(::collection::count c, ::collection::count * pcAllocated)
40
{
41
42
memsize sizeAllocated = 0;
43
44
auto
p = (TYPE*)allocator()->allocate(
sizeof
(TYPE) * c, &sizeAllocated);
45
46
if
(pcAllocated)
47
{
48
49
*pcAllocated = sizeAllocated /
sizeof
(TYPE);
50
51
}
52
53
return
p;
54
55
}
56
57
58
inline
void
free(TYPE* p)
59
{
60
61
allocator()->free((
void
*)p);
62
63
}
64
65
66
};
67
68
69
70
template
<
class
TYPE, enum_memory t_ememory >
71
class
typed_memory
72
{
73
public
:
74
75
76
inline ::heap::memory * memory() { return ::acme::get()->m_pheapmanagement->memory(t_ememory); }
77
78
79
inline
TYPE * allocate(::collection::count c, const_char_pointer pszFile, ::i32 iLine)
80
{
81
82
return
(TYPE *)memory()->allocate_debug(
sizeof
(TYPE) * c, 0, pszFile, iLine);
83
84
}
85
86
87
inline
TYPE * allocate(::collection::count c, ::collection::count * pcAllocated)
88
{
89
90
memsize sizeAllocated = 0;
91
92
auto
p = (TYPE *)memory()->allocate(
sizeof
(TYPE) * c, &sizeAllocated);
93
94
if
(pcAllocated)
95
{
96
97
*pcAllocated = sizeAllocated /
sizeof
(TYPE);
98
99
}
100
101
return
p;
102
103
}
104
105
106
inline
void
free(TYPE * p)
107
{
108
109
memory()->free((
void
*)p);
110
111
}
112
113
114
};
115
//
116
//
117
// //template < typename TYPE >
118
// //class def :
119
// // public typed_allocator < TYPE>
120
// //{
121
//
122
// //};
123
//
124
//
125
// //template < typename TYPE >
126
// //class processor_cache_oriented : // would it help for data-orientation-assumation ??!?!
127
// // public typed_allocator < TYPE, processor_cache_oriented_memory_allocator >
128
// //{
129
//
130
//
131
// //};
132
//
133
//
134
// //template < typename TYPE >
135
// //class sys :
136
// // public allocator < TYPE, ::heap::system_memory_allocator>
137
// //{
138
//
139
// //};
140
//
141
//
142
//
143
}
// namespace heap
144
//
145
146
namespace
allocator
147
{
148
149
150
template
<
typename
TYPE >
151
class
allocator
152
{
153
public
:
154
155
//::heap::typed_allocator < TYPE > * m_ptypedallocator;
156
157
inline
void
construct(TYPE * p)
158
{
159
constructor::nodef< TYPE >::construct(p);
160
}
161
162
inline
void
construct_count(TYPE * p, ::collection::count c)
163
{
164
constructor::nodef< TYPE >::construct_count(p, c);
165
166
}
167
168
169
inline
void
destruct(TYPE * p)
170
{
171
172
destructor::nodef < TYPE >::destruct(p);
173
174
}
175
176
177
inline
void
destruct_count(TYPE * p, ::collection::count c)
178
{
179
180
destructor::nodef < TYPE >::destruct_count(p, c);
181
182
}
183
184
185
inline
void
copy(TYPE * pdst,
const
TYPE * psrc)
186
{
187
188
copier::def< TYPE >::copy(pdst, psrc);
189
190
}
191
192
193
inline
void
copy_count(TYPE * pdst,
const
TYPE * psrc, ::collection::count c)
194
{
195
196
copier::def< TYPE >::copy_count(pdst, psrc, c);
197
198
}
199
200
201
inline
void
copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE & src)
202
{
203
204
while
(c > 0)
205
{
206
207
copy(pdst, &src);
208
209
pdst++;
210
211
c--;
212
213
}
214
215
}
216
217
218
inline
void
copy_construct_array(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
219
{
220
221
while
(c > 0)
222
{
223
224
copy(pdst, psrc);
225
226
c--;
227
228
pdst++;
229
230
psrc++;
231
232
}
233
234
}
235
236
237
inline
void
rear_copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
238
{
239
240
while
(c > 0)
241
{
242
243
c--;
244
245
copy(pdst, psrc + c);
246
247
pdst++;
248
249
}
250
251
}
252
253
254
//inline TYPE * alloc(::collection::count c)
255
//{
256
257
// return m_ptypedallocator->allocate(c);
258
259
//}
260
261
262
//inline void _free(TYPE * p)
263
//{
264
265
// m_ptypedallocator->free(p);
266
267
//}
268
269
};
270
271
272
template
<
typename
TYPE >
273
class
def
:
274
protected
constructor::def
<TYPE>,
275
protected
copier::def
<TYPE>,
276
protected
destructor::def
<TYPE>
277
{
278
public
:
279
280
281
inline
void
construct(TYPE * p)
282
{
283
284
constructor::def< TYPE >::construct(p);
285
286
}
287
288
289
inline
void
construct_count(TYPE * p, ::collection::count c)
290
{
291
292
constructor::def< TYPE >::construct_count(p, c);
293
294
}
295
296
297
inline
void
destruct(TYPE * pointer)
298
{
299
300
destructor::def< TYPE>::destruct(pointer);
301
302
}
303
304
305
inline
void
destruct_count(TYPE * pointer, ::collection::count c)
306
{
307
308
destructor::def< TYPE>::destruct_count(pointer, c);
309
310
}
311
312
313
inline
void
copy(TYPE * pdst,
const
TYPE * psrc)
314
{
315
316
copier::def< TYPE >::copy(pdst, psrc);
317
318
}
319
320
321
inline
void
copy_count(TYPE * pdst,
const
TYPE * psrc, ::collection::count c)
322
{
323
324
copier::def< TYPE >::copy_count(pdst, psrc, c);
325
326
}
327
328
329
inline
void
copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE & src)
330
{
331
332
while
(c > 0)
333
{
334
335
::new (pdst) TYPE(src);
336
337
pdst++;
338
339
c--;
340
341
}
342
343
}
344
345
346
inline
void
copy_construct_array(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
347
{
348
349
while
(c > 0)
350
{
351
352
::new (pdst) TYPE(*psrc);
353
354
c--;
355
356
pdst++;
357
358
psrc++;
359
}
360
361
}
362
363
364
inline
void
rear_copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
365
{
366
367
while
(c > 0)
368
{
369
370
c--;
371
372
::new (pdst) TYPE(psrc[c]);
373
374
pdst++;
375
376
}
377
378
}
379
380
381
//inline TYPE * alloc(::collection::count c, const_char_pointer pszFile, ::i32 iLine)
382
//{
383
384
// return m_ptypedallocator->allocate(c, pszFile, iLine);
385
386
//}
387
//inline TYPE * alloc(::collection::count c)
388
//{
389
390
// return m_ptypedallocator->allocate(c);
391
392
//}
393
394
395
396
//inline void free(TYPE * p)
397
//{
398
399
// m_ptypedallocator->free(p);
400
401
//}
402
403
404
};
405
406
407
408
template
<
typename
TYPE >
409
class
rawcopy
:
410
public
constructor::def
< TYPE >,
411
public
destructor::def
< TYPE>
412
{
413
414
public
:
415
416
inline
void
construct(TYPE * p)
417
{
418
constructor::def< TYPE >::construct(p);
419
}
420
421
inline
void
construct_count(TYPE * p, ::collection::count c)
422
{
423
constructor::def< TYPE >::construct_count(p, c);
424
}
425
426
427
inline
void
destruct(TYPE * pointer)
428
{
429
430
destructor::def< TYPE>::destruct(pointer);
431
432
}
433
434
435
inline
void
destruct_count(TYPE * pointer, ::collection::count c)
436
{
437
438
destructor::def< TYPE>::destruct_count(pointer, c);
439
440
}
441
442
443
inline
void
copy(TYPE * pdst,
const
TYPE * psrc)
444
{
445
446
memory_transfer(pdst, psrc,
sizeof
(TYPE));
447
448
}
449
450
451
inline
void
copy_count(TYPE * pdst,
const
TYPE * psrc, ::collection::count c)
452
{
453
454
memory_transfer(pdst, psrc,
sizeof
(TYPE) * c);
455
456
}
457
458
459
inline
void
copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE & src)
460
{
461
462
/* while (c > 0)
463
{
464
copy(pdst, &src);
465
c--;
466
}*/
467
468
throw_exception(error_not_supported);
469
470
}
471
472
473
inline
void
copy_construct_array(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
474
{
475
476
/* while (c > 0)
477
{
478
copy(pdst, &src);
479
c--;
480
psrc++;
481
}*/
482
483
throw_exception(error_not_supported);
484
485
}
486
487
488
inline
void
rear_copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
489
{
490
491
/* while (c > 0)
492
{
493
copy(pdst, &src);
494
c--;
495
psrc++;
496
}*/
497
498
throw_exception(error_not_supported);
499
500
}
501
502
503
//inline TYPE * alloc(::collection::count c, const_char_pointer pszFile, ::i32 iLine)
504
//{
505
506
// m_ptypedallocator->alloc(c, pszFile, iLine);
507
508
//}
509
//inline TYPE * alloc(::collection::count c)
510
//{
511
512
// m_ptypedallocator->alloc(c);
513
514
//}
515
516
517
//inline void free(TYPE * p)
518
//{
519
520
// m_ptypedallocator->free(p);
521
522
//}
523
524
525
};
526
527
528
template
<
typename
TYPE >
529
class
nodef
530
{
531
public
:
532
533
534
inline
void
construct(TYPE * p)
535
{
536
537
constructor::nodef< TYPE >::construct(p);
538
539
}
540
541
542
inline
void
construct_count(TYPE * p, ::collection::count c)
543
{
544
545
constructor::nodef< TYPE >::construct_count(p, c);
546
547
}
548
549
550
inline
void
destruct(TYPE * pointer)
551
{
552
553
destructor::nodef< TYPE>::destruct(pointer);
554
555
}
556
557
558
inline
void
destruct_count(TYPE * pointer, ::collection::count c)
559
{
560
561
destructor::nodef< TYPE>::destruct_count(pointer, c);
562
563
}
564
565
566
inline
void
copy(TYPE * pdst,
const
TYPE * psrc)
567
{
568
569
copier::def< TYPE >::copy(pdst, psrc);
570
571
}
572
573
574
inline
void
copy_count(TYPE * pdst,
const
TYPE * psrc, ::collection::count c)
575
{
576
577
copier::def< TYPE >::copy_count(pdst, psrc, c);
578
579
}
580
581
582
inline
void
copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE & src)
583
{
584
585
while
(c > 0)
586
{
587
588
copy(pdst, &src);
589
590
pdst++;
591
592
c--;
593
594
}
595
596
}
597
598
599
inline
void
copy_construct_array(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
600
{
601
602
while
(c > 0)
603
{
604
605
copy(pdst, psrc);
606
607
c--;
608
609
pdst++;
610
611
psrc++;
612
613
}
614
615
}
616
617
618
inline
void
rear_copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
619
{
620
621
while
(c > 0)
622
{
623
624
c--;
625
626
copy(pdst, psrc + c);
627
628
pdst++;
629
630
}
631
632
}
633
634
635
636
/* inline TYPE * alloc(::collection::count c, const_char_pointer pszFile, ::i32 iLine)
637
{
638
639
return m_ptypedallocator->alloc(c, pszFile, iLine);
640
641
}
642
inline TYPE * alloc(::collection::count c)
643
{
644
645
m_ptypedallocator->alloc(c);
646
647
}
648
649
650
inline void _free(TYPE * p)
651
{
652
653
m_ptypedallocator->free(p);
654
655
}
656
*/
657
658
};
659
660
661
template
<
typename
TYPE >
662
class
raw
663
{
664
public
:
665
666
667
inline
void
construct(TYPE * p)
668
{
669
670
constructor::nodef< TYPE >::construct(p);
671
672
}
673
674
675
inline
void
construct_count(TYPE * p, ::collection::count c)
676
{
677
678
constructor::nodef< TYPE >::construct_count(p, c);
679
680
}
681
682
683
inline
void
destruct(TYPE * pointer)
684
{
685
686
destructor::nodef< TYPE>::destruct(pointer);
687
688
}
689
690
691
inline
void
destruct_count(TYPE * pointer, ::collection::count c)
692
{
693
694
destructor::nodef< TYPE>::destruct_count(pointer, c);
695
696
}
697
698
699
inline
void
copy(TYPE * pdst,
const
TYPE * psrc)
700
{
701
702
memory_transfer(pdst, psrc,
sizeof
(TYPE));
703
704
}
705
706
707
inline
void
copy_count(TYPE * pdst,
const
TYPE * psrc, ::collection::count c)
708
{
709
710
memory_transfer(pdst, psrc,
sizeof
(TYPE) * c);
711
712
}
713
714
715
inline
void
copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE & src)
716
{
717
718
while
(c > 0)
719
{
720
721
copy(pdst, &src);
722
723
pdst++;
724
725
c--;
726
727
}
728
729
}
730
731
732
inline
void
copy_construct_array(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
733
{
734
735
while
(c > 0)
736
{
737
738
copy(pdst, psrc);
739
740
c--;
741
742
pdst++;
743
744
psrc++;
745
746
}
747
748
}
749
750
751
inline
void
rear_copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
752
{
753
754
while
(c > 0)
755
{
756
757
c--;
758
759
copy(pdst, psrc + c);
760
761
pdst++;
762
763
}
764
765
}
766
767
768
//inline TYPE * alloc(::collection::count c, const_char_pointer pszFile, ::i32 iLine)
769
//{
770
771
// return m_ptypedallocator->alloc(c, pszFile, iLine);
772
773
//}
774
//inline TYPE * alloc(::collection::count c)
775
//{
776
777
// m_ptypedallocator->alloc(c);
778
779
//}
780
781
782
//inline void free(TYPE * p)
783
//{
784
785
// m_ptypedallocator->free(p);
786
787
//}
788
789
790
};
791
792
793
template
<
typename
TYPE >
794
class
zero
:
795
public
constructor::zero
< TYPE >,
796
public
destructor::nodef
< TYPE>,
797
public
copier::def
< TYPE >
798
{
799
public
:
800
801
802
inline
void
construct(TYPE * p)
803
{
804
805
constructor::zero< TYPE >::construct(p);
806
807
}
808
809
810
inline
void
construct_count(TYPE * p, ::collection::count c)
811
{
812
813
constructor::zero< TYPE >::construct_count(p, c);
814
815
}
816
817
818
inline
void
destruct(TYPE * p)
819
{
820
821
destructor::nodef< TYPE>::destruct(p);
822
823
}
824
825
826
inline
void
destruct_count(TYPE * p, ::collection::count c)
827
{
828
829
destructor::nodef< TYPE>::destruct_count(p, c);
830
831
}
832
833
834
inline
void
copy(TYPE * pdst,
const
TYPE * psrc)
835
{
836
837
copier::def< TYPE >::copy(pdst, psrc);
838
839
}
840
841
842
inline
void
copy_count(TYPE * pdst,
const
TYPE * psrc, ::collection::count c)
843
{
844
845
copier::def< TYPE >::copy_count(pdst, psrc, c);
846
847
}
848
849
850
inline
void
copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE & src)
851
{
852
853
while
(c > 0)
854
{
855
856
copy(pdst, &src);
857
858
pdst++;
859
860
c--;
861
862
}
863
864
}
865
866
867
inline
void
copy_construct_array(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
868
{
869
870
while
(c > 0)
871
{
872
873
copy(pdst, psrc);
874
875
pdst++;
876
877
c--;
878
879
psrc++;
880
881
}
882
883
}
884
885
886
inline
void
rear_copy_construct_count(TYPE * pdst, ::collection::count c,
const
TYPE * psrc)
887
{
888
889
while
(c > 0)
890
{
891
892
c--;
893
894
copy(pdst, psrc + c);
895
896
pdst++;
897
898
}
899
900
}
901
902
903
//inline TYPE * alloc(::collection::count c, const_char_pointer pszFile, ::i32 iLine)
904
//{
905
906
// return m_ptypedallocator->alloc(c, pszFile, iLine);
907
908
//}
909
//inline TYPE * alloc(::collection::count c)
910
//{
911
912
// return m_ptypedallocator->alloc(c);
913
914
//}
915
916
917
//inline void free(TYPE * p)
918
//{
919
920
// m_ptypedallocator->free(p);
921
922
//}
923
924
925
};
926
//
927
// template < typename TYPE >
928
// class sys
929
// {
930
//
931
// public:
932
//
933
// inline void construct(TYPE * p)
934
// {
935
// constructor::def< TYPE >::construct(p);
936
// }
937
//
938
// inline void construct_count(TYPE * p, ::collection::count c)
939
// {
940
// constructor::def< TYPE >::construct_count(p, c);
941
//
942
// }
943
//
944
// inline void destruct(TYPE * p)
945
// {
946
// destructor::def< TYPE>::destruct(p);
947
// }
948
// inline void destruct_count(TYPE * p, ::collection::count c)
949
// {
950
// destructor::def< TYPE>::destruct_count(p, c );
951
// }
952
//
953
//
954
// inline void copy(TYPE * pdst, const TYPE * psrc)
955
// {
956
//
957
// copier::def< TYPE >::copy(pdst, psrc);
958
//
959
// }
960
//
961
//
962
// inline void copy_count(TYPE * pdst, const TYPE * psrc, ::collection::count c)
963
// {
964
//
965
// copier::def< TYPE >::copy_count(pdst, psrc, c);
966
//
967
// }
968
//
969
// inline void copy_construct_count(TYPE * pdst, ::collection::count c, const TYPE & src)
970
// {
971
//
972
// while (c > 0)
973
// {
974
// copy(pdst, &src);
975
// pdst++;
976
// c--;
977
// }
978
//
979
// }
980
//
981
//
982
// inline void copy_construct_array(TYPE * pdst, ::collection::count c, const TYPE * psrc)
983
// {
984
//
985
// while (c > 0)
986
// {
987
// copy(pdst, psrc);
988
// c--;
989
// pdst++;
990
// psrc++;
991
// }
992
//
993
// }
994
//
995
//
996
//#if MEMDLEAK || defined(__MCRTDBG)
997
// inline TYPE * alloc(::collection::count c, const_char_pointer pszFile, ::i32 iLine)
998
// {
999
//
1000
// return heap::sys < TYPE >::alloc(c, pszFile, iLine);
1001
//
1002
// }
1003
//#else
1004
// inline TYPE * alloc(::collection::count c)
1005
// {
1006
//
1007
// return heap::sys < TYPE >::alloc(c);
1008
//
1009
// }
1010
//#endif
1011
//
1012
// inline void _free(TYPE * p)
1013
// {
1014
//
1015
// heap::sys < TYPE >::_free(p);
1016
//
1017
// }
1018
//
1019
//
1020
// };
1021
1022
1023
}
// namespace allocator
1024
1025
1026
allocator::allocator
Definition
typed_memory.h:152
allocator::def
Definition
typed_memory.h:277
allocator::nodef
Definition
typed_memory.h:530
allocator::raw
Definition
typed_memory.h:663
allocator::rawcopy
Definition
typed_memory.h:412
allocator::zero
Definition
typed_memory.h:798
constructor::def
Definition
typed.h:85
constructor::zero
Definition
typed.h:109
copier::def
Definition
typed.h:226
destructor::def
Definition
typed.h:167
destructor::nodef
Definition
typed.h:201
heap::operating_system_typed_memory
Definition
typed_memory.h:14
heap::typed_memory
Definition
typed_memory.h:72
memory
typed_memory.h
Generated by
1.17.0