Date: Fri, 27 Dec 2024 15:56:09 -0700
Can you send a reproducible example on https://quick-bench.com?
Cheers,
Jeremy
On Fri, Dec 27, 2024 at 15:49 Фаррах Фаттахов <farrakhfattahov_at_[hidden]>
wrote:
> I ran the tests several times, changing only the container and nothing
> more, but it is possible that the code was really incorrect somewhere,
> although I don't believe it. By the way, I usually set constructors and
> destructors to default, sometimes they (especially destructors) work at the
> wrong time, but I think this can also be explained by my inexperience in
> using them.
>
> Сб, 28 дек. 2024 г. в 01:37, Jeremy Rifkin <rifkin.jer_at_[hidden]>:
>
>> > I meant that reset() simply resets the mSize counter, without
>> performing any other logic.
>>
>> If the items in the vector aren’t trivially destructible, this is a bug.
>> Consider a vector of strings, you now have a memory leak.
>>
>> > clear() from std::vector was noticeably faster than my `simple'
>> clear() from FE2D::dynamic_array, but still fell short of reset()
>>
>> I would be happy to look at implementation/benchmarks but my guess is
>> this can be explained either by incorrect code or by incorrect benchmark
>> setup. If the vector contents are trivially destructible then the extra
>> logic from clear() is a no-op.
>>
>> Cheers,
>> Jeremy
>>
>> On Fri, Dec 27, 2024 at 15:30 Фаррах Фаттахов <farrakhfattahov_at_[hidden]>
>> wrote:
>>
>>> I meant that reset() simply resets the mSize counter, without performing
>>> any other logic. However, I can't help but notice that during my tests,
>>> clear() from std::vector was noticeably faster than my `simple' clear()
>>> from FE2D::dynamic_array, but still fell short of reset()
>>>
>>> Сб, 28 дек. 2024 г. в 01:23, Jeremy Rifkin <rifkin.jer_at_[hidden]>:
>>>
>>>> > Here reset() works like clear(), but much faster
>>>>
>>>> Why? If you have in mind the destructor calls, those are important and
>>>> can’t just be discarded. They will be optimized away by the compiler if the
>>>> items are trivially destructed.
>>>>
>>>> Cheers,
>>>> Jeremy
>>>>
>>>> On Fri, Dec 27, 2024 at 14:57 Фаррах Фаттахов via Std-Proposals <
>>>> std-proposals_at_[hidden]> wrote:
>>>>
>>>>> After working with SFML, I so hated std::vector (I was a bad
>>>>> programmer back then and didn't know about the reserve() function, which
>>>>> led to not understanding why std::vector is so slow, while a simple array
>>>>> performs much better). As a result, in my new project i created my own
>>>>> version of std::vector - FE2D::dynamic_array. And there, from the
>>>>> beginning i created one useful function - reset()
>>>>> ```C++
>>>>>
>>>>> // Reset the Size of Dynamic Array to Zero, but it's don't Touches the Real Occupied Memory of Dynamic Array
>>>>> void reset() { mSize = 0; }
>>>>> ```
>>>>>
>>>>> Instead of clear() it's just setting mSize to zero. It's very useful
>>>>> in the situations like
>>>>>
>>>>> ```C++
>>>>> void Render() { // It's called every frame
>>>>> // Add a sprites to the FE2D::dynamic_array to draw it later
>>>>> m_Renderer.AddSprite(m_Sprite_0);
>>>>> m_Renderer.AddSprite(m_Sprite_1);
>>>>> m_Renderer.AddSprite(m_Sprite_2);
>>>>> ...
>>>>> // Draw the Sprites and reset the dynamic arrays to prepare it for the next frame
>>>>> m_Renderer.RenderSprites();
>>>>> }
>>>>> ```
>>>>> Here reset() works like clear(), but much faster
>>>>>
>>>>> In the std::vector or std::deque is no functions like reset() and i
>>>>> want to add it there, especially sometimes i get errors because my
>>>>> FE2D::dynamic_array is not so good like std::vector and i have to use it
>>>>> instead of mine, but there is no function i need. I think reset() will be
>>>>> nice thing for std::vector.
>>>>> --
>>>>> Std-Proposals mailing list
>>>>> Std-Proposals_at_[hidden]
>>>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>>>
>>>>
Cheers,
Jeremy
On Fri, Dec 27, 2024 at 15:49 Фаррах Фаттахов <farrakhfattahov_at_[hidden]>
wrote:
> I ran the tests several times, changing only the container and nothing
> more, but it is possible that the code was really incorrect somewhere,
> although I don't believe it. By the way, I usually set constructors and
> destructors to default, sometimes they (especially destructors) work at the
> wrong time, but I think this can also be explained by my inexperience in
> using them.
>
> Сб, 28 дек. 2024 г. в 01:37, Jeremy Rifkin <rifkin.jer_at_[hidden]>:
>
>> > I meant that reset() simply resets the mSize counter, without
>> performing any other logic.
>>
>> If the items in the vector aren’t trivially destructible, this is a bug.
>> Consider a vector of strings, you now have a memory leak.
>>
>> > clear() from std::vector was noticeably faster than my `simple'
>> clear() from FE2D::dynamic_array, but still fell short of reset()
>>
>> I would be happy to look at implementation/benchmarks but my guess is
>> this can be explained either by incorrect code or by incorrect benchmark
>> setup. If the vector contents are trivially destructible then the extra
>> logic from clear() is a no-op.
>>
>> Cheers,
>> Jeremy
>>
>> On Fri, Dec 27, 2024 at 15:30 Фаррах Фаттахов <farrakhfattahov_at_[hidden]>
>> wrote:
>>
>>> I meant that reset() simply resets the mSize counter, without performing
>>> any other logic. However, I can't help but notice that during my tests,
>>> clear() from std::vector was noticeably faster than my `simple' clear()
>>> from FE2D::dynamic_array, but still fell short of reset()
>>>
>>> Сб, 28 дек. 2024 г. в 01:23, Jeremy Rifkin <rifkin.jer_at_[hidden]>:
>>>
>>>> > Here reset() works like clear(), but much faster
>>>>
>>>> Why? If you have in mind the destructor calls, those are important and
>>>> can’t just be discarded. They will be optimized away by the compiler if the
>>>> items are trivially destructed.
>>>>
>>>> Cheers,
>>>> Jeremy
>>>>
>>>> On Fri, Dec 27, 2024 at 14:57 Фаррах Фаттахов via Std-Proposals <
>>>> std-proposals_at_[hidden]> wrote:
>>>>
>>>>> After working with SFML, I so hated std::vector (I was a bad
>>>>> programmer back then and didn't know about the reserve() function, which
>>>>> led to not understanding why std::vector is so slow, while a simple array
>>>>> performs much better). As a result, in my new project i created my own
>>>>> version of std::vector - FE2D::dynamic_array. And there, from the
>>>>> beginning i created one useful function - reset()
>>>>> ```C++
>>>>>
>>>>> // Reset the Size of Dynamic Array to Zero, but it's don't Touches the Real Occupied Memory of Dynamic Array
>>>>> void reset() { mSize = 0; }
>>>>> ```
>>>>>
>>>>> Instead of clear() it's just setting mSize to zero. It's very useful
>>>>> in the situations like
>>>>>
>>>>> ```C++
>>>>> void Render() { // It's called every frame
>>>>> // Add a sprites to the FE2D::dynamic_array to draw it later
>>>>> m_Renderer.AddSprite(m_Sprite_0);
>>>>> m_Renderer.AddSprite(m_Sprite_1);
>>>>> m_Renderer.AddSprite(m_Sprite_2);
>>>>> ...
>>>>> // Draw the Sprites and reset the dynamic arrays to prepare it for the next frame
>>>>> m_Renderer.RenderSprites();
>>>>> }
>>>>> ```
>>>>> Here reset() works like clear(), but much faster
>>>>>
>>>>> In the std::vector or std::deque is no functions like reset() and i
>>>>> want to add it there, especially sometimes i get errors because my
>>>>> FE2D::dynamic_array is not so good like std::vector and i have to use it
>>>>> instead of mine, but there is no function i need. I think reset() will be
>>>>> nice thing for std::vector.
>>>>> --
>>>>> Std-Proposals mailing list
>>>>> Std-Proposals_at_[hidden]
>>>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>>>
>>>>
Received on 2024-12-27 22:56:22