473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Allocators, I don't know what I'm talking about.

3 2Bits
Hello Der,

I'm trying to make a ECS in c++ and started exploring the existing material a little, going down the rabbit hole I ended up finding out about special allocators.

I think I get the theory behind the allocators, and have seen multiple (around 5) videos from cpp con and one from code::dive 2018 about allocators, and I do get that using allocators<typename> is bad and that you should use std::pmr::datatype<typename, &(allocator)> instead.

What I specifically don't understand is what function other than : new, malloc, realloc, calloc (these are general allocators right?). do you use to get the memory in the first place? Like what is that one function that gives you a block of memory on the ram to work with so that nothing else touches it? What does the actual grabbing memory out of thin air work?

Do you like just get an array of some required size in bytes, and then deal with that ? Or is there a function that you can call so you don't have to create an array? This seems kind of contradictory?

I apologize if I make absolutely no sense, but can someone please help me out... I don't think I'm intelligent enough to figure this out on my own...
usps tracking showbox speed test
Jun 17 '20 #1
2 1606
Banfa
9,065 Expert Mod 8TB
malloc, realloc, calloc*are C functions, in general you should not use them in C++.

You should be using new, the major difference is that malloc, realloc, calloc*allocates you a block of uninitialized memory where as new allocates the block of memory and then calls the appropriate constructor on it to initialize the memory.

std::pmr is all very well but it is C++17 and there is plenty of development still going on using C++11 and C++14 so you need to know how to use new correctly.
Jun 17 '20 #2
dev7060
636 Expert 512MB
What I specifically don't understand is what function other than : new, malloc, realloc, calloc (these are general allocators right?). do you use to get the memory in the first place?
General-purpose languages provide the basic functions/keywords to be used to make software in the widest variety of application domains. Custom data structures can be made according to the needs by making use of the basic entities.

Like what is that one function that gives you a block of memory on the ram to work with so that nothing else touches it? What does the actual grabbing memory out of thin air work?
When you reserve a memory space using a variable, array, dynamic allocation, etc., it is untouchable by any program/process in regards to reallocation. No other process can reallocate that memory to something else unless the cell spaces are freed and are no more tagged as "in use". If it could, there would be no concept of memory leakage. However, that block of memory can be manipulated via manual programming using pointers. That's why pointers need to be dealt with care. Languages like Java don't make use of the pointers directly for security purposes.
Jun 17 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: hojjatnikan | last post by:
please help me this code 62EH&5gx0wiqoQFw is this name ( Belux) but i dont know how convert it i dont know the algorithm of this code plead help me
20
by: raylopez99 | last post by:
Dvorak is always interesting, albeit speculative. What hidden gem has he found in Vista that helps developers? It can't be .NET/CLI, that's been out forever. RL Vista rollout hides reality...
20
by: Steven D'Aprano | last post by:
Am I the only one who finds that I'm writing more documentation than code? I recently needed to write a function to generate a rank table from a list. That is, a list of ranks, where the rank of...
63
by: David Mathog | last post by:
There have been a series of questions about directory operations, all of which have been answered with "there is no portable way to do this". This raises the perfectly reasonable question, why,...
21
by: stephenrussett | last post by:
Ok i what i am trying to do is: I have a query that pumps out information like this: (1) (2) (3) (4) (5) 1 1 Cooper Street NS...
2
by: Tiruak | last post by:
Hi there. Thanks in advance for the people reading and trying to help. I'm very begginer using flash and action script, and I tryed to do this one navigation menu. Since I dont have experience...
2
by: Sreenivas | last post by:
I dont know how to compile cpp programs with gcc as i am new to gcc and cpp. could anybody help me out? Thanks&Regards, Srinivas Reddy Thatiparthy.
2
by: shwetaT | last post by:
i m working in php domain and i dont know much about php,so will u plz suggest me some good sites through which i learn php very well n fast
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.