Anonymous
I don't get you?
I bet you cannot build Chromium on the right phone
Anonymous
I bet you cannot build Chromium on the right phone
Yh buh there are other alternative when you are using proot
Артём
To the question about new vs malloc / delete vs free. Is it better to use free instead of delete to the pointer I reallocated just before?
Артём
To the question about new vs malloc / delete vs free. Is it better to use free instead of delete to the pointer I reallocated just before?
I've read, that is better to only use delete after new, and free after malloc. So here comes the question.
vinícius*
If you reserved memory with new, you're not supposed to realloc it
Артём
You can only realloc that which has been `malloc`ed
Why can't I realloc what has been new'ed?
vinícius*
Because they're different things, using different underlying data structures
vinícius*
It may work if you test it, but it's undefined behaviour
vinícius*
if what you're doing is using realloc to expand an array, you should probably just use std::vector instead
Wisenky
anyone can help me to fix boot menu on my laptop . I installed a linux distro many times but still just finds windows boot manager .
Wisenky
:(
Anonymous
:(
I removed it now because I remember you
Wisenky
thanks sir
Anonymous
I'll help
Andrew
anyone can help me to fix boot menu on my laptop . I installed a linux distro many times but still just finds windows boot manager .
https://help.ubuntu.com/community/Boot-Repair , you can find for other non debian based distro too
Anonymous
Ask your question in #ot chat or try to find a chat here @en_it_chats
Wisenky
okay
Артём
If you reserved memory with new, you're not supposed to realloc it
hence, it is not recommended to delete what I malloc'ed and realloc'ed? Should I only use free in this case?
Anonymous
hence, it is not recommended to delete what I malloc'ed and realloc'ed? Should I only use free in this case?
Yes But please Don't allocate memory yourself Use containers or smart pointers
vinícius*
Are there even good uses of new anymore ?
Anonymous
Only for senior/expert level stuff I suppose
vinícius*
Only for senior/expert level stuff I suppose
I honestly can't remember the last time I've seen new/delete in a big C++ project
vinícius*
What's TBB?
Anonymous
Threading Building Blocks
Vlad
What's TBB?
google "intel tbb"
Anonymous
Lib for parallelism and multithreading without pain in the ass
Anonymous
google "intel tbb"
Now it's oneapi TBB
Vlad
Lib for parallelism and multithreading without pain in the ass
Is it even possible without the latter? :P
Anonymous
Is it even possible without the latter? :P
Don't understand the question
Vlad
Don't understand the question
I mean multithreading and pain in the arse go hand to hand.
Anonymous
TBB makes it easier
It's like a lubricant
Vlad
TBB makes it easier
But you're constrained to x86 then?
Артём
Yes But please Don't allocate memory yourself Use containers or smart pointers
Ohh, that's exactly my task to implement analog of vector without STL. :D Do I do it correctly, allocating memory with malloc, resizing it with realloc and destructing with free?
Артём
As I understood, it's wrong way to use new when constructing object, because later I'll have to realloc'ate it?
Anonymous
But you're constrained to x86 then?
No It supported in different architectures You can checkout CMakeLists in oneTBB-2021 branch what platforms it support X86, ARM, mips for sure
Vlad
Vector implementation shall not use realloc
What you do instead is allocate memory by sizeof(T) * power_of_two and then call placement new.
Артём
What you do instead is allocate memory by sizeof(T) * power_of_two and then call placement new.
Why not realloc? It does exactly the same, furthermore it may just expand or contract the existing area, without allocating a new memory block and copying memory area.
Vlad
But it's not the way it's done in STL for that reason
Артём
Just remember to call placement new on push_back
I'm sorry I don't understand what you mean under 'placement new'?
Vlad
I'm sorry I don't understand what you mean under 'placement new'?
template<typename T> T* alloc() { static constexpr size_t size = (1 << 20); // 1 megabyte static std::byte storage[size]; static size_t offset = 0; T* ptr = new (storage + offset) T; offset += alignof(T); return ptr; } That's a very crude example of usage but I hope you'll get it
Konstantin
I'm sorry I don't understand what you mean under 'placement new'?
I hope I can share URL here. This should help https://en.cppreference.com/w/cpp/language/new
Selmon boi
Can someone share basics of c++
Konstantin
Can someone share basics of c++
That's pretty much sums it up: “C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.” ― Bjarne Stroustrup P.S. read the rules, please.
olli
/warn no need to repost
Артём
template<typename T> T* alloc() { static constexpr size_t size = (1 << 20); // 1 megabyte static std::byte storage[size]; static size_t offset = 0; T* ptr = new (storage + offset) T; offset += alignof(T); return ptr; } That's a very crude example of usage but I hope you'll get it
Ok, thanks for introduction placement new for me. But I still have questions: how to correctly reallocate memory for my vector? placement new here just initializes storage elements on pre-allocated memory.
Артём
So how does memory reallocation work under the hood, if it's not realloc? when used size gets more than reserved and pre-allocated area.
Sammie
/warn
Sammie
OK ma
Sammie
It was a mistake
Twenty19TEight
#include <iostream> using namespace std; class test1{ public: void setname(string x){ name = x; } string getname(){ return name; } private: string name; } int main(){ test1 t1; t1.setname("Mark"); //how do I get this input from user cout<<t1.getname(); return 0; }
Twenty19TEight
please answer
Twenty19TEight
Men this is my own thing Its not an assignment
Twenty19TEight
Idk how to take that input from user so I asked here
Twenty19TEight
I hope u understand
Twenty19TEight
didn't found any proper help
Sasuke
Idk how to take that input from user so I asked here
Just store the input in a variable and pass that later as a parameter
Twenty19TEight
can u help me out I'm stuck at this from last night
Twenty19TEight
Just store the input in a variable and pass that later as a parameter
I want that input from user using cin or something.... I don't wanna assign it by default
Twenty19TEight
I tried cin>>t1.setname(); cin>>t1.setname(name); Etc But didn't work
Sasuke
I tried cin>>t1.setname(); cin>>t1.setname(name); Etc But didn't work
You want to take input from user and and send it to the class object right?
Twenty19TEight
Yeah
Konstantin
didn't found any proper help
Start with https://en.cppreference.com/w/cpp/io/cin