Ioann_
Hey, dudes, here i wrote some interesting stuff about how can u do your integer divisions - faster. Pls. check this: https://habr.com/ru/post/468581/ #publication #asm #cxx #optimization
Ioann_
Well, here is by Eng. AHTUNG: material is h4rdc0r3, but u will never get c00l unless you understand it.
Ioann_
Hope, i don't get the ban: my goals not for glory or money. Just knowledges for all of us!
Pavel
@Ioann_V, about your article, don't compilers do these optimizations if the denominator is known?
Ioann_
not always. My optimisation is about right shift operation, which not always needed. But compilers insert it always :)
Pavel
I mean what's the difference between vector<int> v; and vector<int> *v = new vector<int>;
In the second case you create it on heap, and need to delete it manually. In my opinion should use the first case whenever possible.
Pavel
Because the second is more error prone
Anonymous
But we don't need to deallocated it manually
Anonymous
right?
Anonymous
Guyzz, how to find the farthest pair of points on a set of points
Pavel
Even the first is allocated in heap.
Nope.. well.. the data is allocated on heap, but the vector itself not (well, that depends too), I don't know what is inside the vector class, there are probably size and a pointer to the data. And in the first case you create the vector on stack if it's local variable (so these two values are on stack), or it's part of the class if it's a member of a class (so the data for the vector is allocated with the class). In the second case you create the vector on heap always and have a pointer to the vector.
Pavel
The second is also can be bad for performance btw, because compiler is forced to fetch vector from RAM just to fetch more data from RAM.
Pavel
I'm not sure that there are two values btw, that's my guess
Lionel
Do we need to have a pointer to the vector explicitly
Lionel
Doesn't it got it's own pointers implicitly
Lionel
Begin and end
Pavel
I meant the pointer that you get from new
Anonymous
The second is also can be bad for performance btw, because compiler is forced to fetch vector from RAM just to fetch more data from RAM.
Didn't get this statement. Everything is allocated in RAM - stack, heap. So what do you mean by explicit fetching from RAM?
Pavel
Didn't get this statement. Everything is allocated in RAM - stack, heap. So what do you mean by explicit fetching from RAM?
That's a deep topic. Not sure you need it right now. To make it short and simple, traversing a pointer sometimes can be slow, because processor needs to wait the data transferred from RAM (if it doesn't have it on caches already). But compilers can reorder operations to fill the processor with useful work while it's waiting for the data. But if you traverse a pointer just to get another pointer to traverse that's harder to improve and there are more chances that processor will be just waiting. But again, that's a deep topic, and everything is more complicated in reality.
Pavel
Well, maybe more overhead than have a stack allocated array
Pavel
But I'm talking about a vector created with new
Ilya
I mean what's the difference between vector<int> v; and vector<int> *v = new vector<int>;
These are different classes of memory this std::vector object belongs to . The later is Dynamic , the first one is unknown depending on the place where declaration took place
Lionel
Basically traversing pointers will generate overhead right. Pointers are not in python, then why it's slower than c++
Ilya
So in general, std:: vector generates overhead?
Every thing generates overhead. So what?
Lionel
What is slower?
Usage of pointers.
Ilya
Usage of pointers.
Compared to what?
Lionel
But, for the first one too the data is present in the heap
I guess data would always be placed in the heap when it comes to vector
Lionel
What I thought of vector is at first they would be allocated on the size and if they need more memory, they would get it from heap. But that's not the case
Lionel
Not the data, the object of std::vector
Yes. Like a name Tag. Info about the data
Anonymous
With the default allocator - yes.
I dont know anyting about allocators. SAD.
Anonymous
Not the data, the object of std::vector
so, you mean the object in the first case is present in the stack and the object in the second case is present in the heap?
Anonymous
So, when the object is present in the stack and gets destroyed, automatically the destructor is called and deallocates the entire data from the heap?
Pavel
so, you mean the object in the first case is present in the stack and the object in the second case is present in the heap?
Basically, yes (except for the case when it's a part of a class that is created on heap)
Anonymous
Why is this so important to you?
IDK, I think I should know this.
Lionel
IDK, I think I should know this.
Bro. Check out stackoverflow
Ilya
what's the default implementation?
To Allocate memory from heap by means of NEW operation
Ilya
the vector itself can be allocated as any memory class. what does that mean
You know memory clases in c and c++? Auto, static, global etc
Ilya
I mean NO.😹
Brilliant!
Anonymous
I checked it. yes I know
Anonymous
😹
Anonymous
Beautiful!
I didn't know that we call them memory classes.🤦‍♀️
Anonymous
Doesn't multimap provide the use of [] operator?
Anonymous
Suppose i want to check if a no. A is mapped to another no. B multimap<int,int> m; doesn't m[A] == B work?
Nader Should
Hi everyone. I need this book's audio for my study If anyone have it please talk to me in the chat.
Pavel
Doesn't multimap provide the use of [] operator?
It doesn't because imagine you have two values for a key, what should it return then?
Anonymous
any function to check that?
Pavel
any function to check that?
You want to check that there's a pair of key-value that contains {A, B}?
Anonymous
You want to check that there's a pair of key-value that contains {A, B}?
I think then I should use map<pair<int,int>, int> m
Anonymous
It will be much better. aint it?
Pavel
It will be much better. aint it?
You also can use std::set<std::pair<int, int>>. Or for multimap get equal_range and search in it (using std::find maybe).