Похожие чаты

What'S a common scenario for you, are you in games,

web, trading, ?

33 ответов

34 просмотра

Past several years was different financial applications but I am looking at getting into trading engines.

Thomas- Автор вопроса
Kenshin Himura
Past several years was different financial applica...

I'm not familiar with what financial applications really do, but if you imagine some kind of web server, you could define a pool of memory blocks used for each request, the number of items in the pool being the max number of concurrent requests, and the size of each block being the max memory each request can use. Then you can take a block from the pool when a request comes in, wrap it in an allocator, and allocate all request-related data into it, then you just reset it or zero it after the response is sent

Thomas
I'm not familiar with what financial applications ...

I understand your scheme. However, remember, the necessity of RAII is more than clean resource deallocation at the end of normal execution. It also protects against exceptions that might abort the execution of your operation, before your clean deallocation at the end of normal execution. That, and sometimes some developers have multiple points of return, which if not careful about, might lead to several resource leaks. A big part of the C++ std library depends on RAII; the std containers, smart pointers, I/O facilities, etc. Same with the most trusted C++ libraries outside std. RAII is the reason we can allocate resource handles on the stack, simplifying code, instead of dealing with pointers every time or the disposal of the resources managed by those handles. For safe, clean, high quality C++, RAII is indispensable.

Thomas- Автор вопроса
Thomas- Автор вопроса
Kenshin Himura
I understand your scheme. However, remember, the n...

resource handles on the stack through RAII doesn't make sense to me

Thomas- Автор вопроса
Thomas- Автор вопроса
Kenshin Himura
I understand your scheme. However, remember, the n...

So there's another language feature that C++ lacks that solves the multiple points of return thing

Thomas
I don't use exceptions either heh

I like exceptions quite a lot in other languages but not sure they can be as good in C++ if you like C-style

Thomas- Автор вопроса
Chiyando
I like exceptions quite a lot in other languages b...

I think any language where the type system doesn't know about them they're real bad

Thomas
resource handles on the stack through RAII doesn't...

It does, 100%. Thing is, constructing objects on the stack in C++ guarantees that their destructor will be called on scope exit, no matter how that exit occurs. Not the same with heap allocated objects; the deallocation has to be done manually, which is a breeding ground for error. Therefore, with RAII, the allocation of the resource is accomplished in the constructor of the handle-like class, while the deallocation is performed in the destructor. This handle object then becomes a convenient interface to using the resource safely, cause the second that handle object goes out of scope, no matter how, it's destructor will be called, thus properly deallocating and disposing the resource. This is exactly what the std library containers, smart pointers, etc are doing.

Thomas
I also don't use C++ stdlib much

If you did, you would know how prevalent and beloved RAII is in C++. Some years back, several C++ authorities/experts spoke AB their favourite C++ features. The most prevalent was a code example, simply, } Yes, that one curly brace was favourite feature. Why? Cause that signifies end of scope, meaning guaranteed calling of destructors for stack objects. RAII is an idiom born out of that.

Thomas- Автор вопроса
Kenshin Himura
It does, 100%. Thing is, constructing objects on ...

I don't really care about this, since I don't find myself making the mistake of not releasing resources, and you could do a bulk approach to this too

Thomas- Автор вопроса
Kenshin Himura
If you did, you would know how prevalent and belov...

Most C++ devs I follow hate it and don't use RAII heh

Thomas- Автор вопроса
Thomas
I don't really care about this, since I don't find...

This is the error of overconfidence, actually. Even seasoned professionals occasionally make the simplest mistakes. You are also not considering the factor of dealing with other people's code, especially in large code bases. And no, bulk approaches are not ideal for a large many developers for their needs; you may as well suggest garbage collection. One of the reasons people choose C++ is it guarantees deterministic destruction of local objects; you know exactly when it will happen, and we take advantage of that. This is the backbone of RAII.

Thomas- Автор вопроса
Kenshin Himura
This is the error of overconfidence, actually. Eve...

I don't think you understand what I mean by bulk approach, I'm talking about collecting file handles into a container and closing them all at once

Thomas- Автор вопроса
Kenshin Himura
This is the error of overconfidence, actually. Eve...

Try a language which conventionally uses defer for closing handles, and you'll see it's hard to make the mistake

Thomas
I don't think you understand what I mean by bulk a...

Yes and the bulk container handles the closing because of RAII. So RAII is a useful concept that you will eventually end up using anyway

Thomas
Most C++ devs I follow hate it and don't use RAII ...

The C++ devs you follow are plainly not familiar with the actual strengths of C++. Follow the C++ devs that are actual recognized authorities in the community, who are part of the Standards Committee, who have driven the development of C++ for the past several decades, or the major C++ libraries. Not one would eschew RAII or be a proponent of manual resource disposal. Not one. Stroustrup. Sutter. Abraham. Parent. Sutton. Hinnant. Carruth. Lavavej (STL). Dos Reis. Voutilainen. Gregory. Winters. Niebler. Vandevoorde. Lelbach. Plauger. Austern. Dionne. Turner. Chen. Alexandrescu. Dusíková. Meyers. Berris. Josuttis. Gregor. etc. The above is but a small list of the most influential people in the community. I challenge you to find one who hates RAII.

Thomas- Автор вопроса
VD
Yes and the bulk container handles the closing bec...

No, you'd call the bulk container manually to close all

Thomas- Автор вопроса
Kenshin Himura
The C++ devs you follow are plainly not familiar w...

They're very familiar with it lol, they're mostly oldschool gamedev people

Thomas
I don't think you understand what I mean by bulk a...

You are still keeping the resources open for longer than necessary. And, in C++, the example you gave will definitely be handled by a RAII class. Your example begs for a library solution. The class will have functions that will add the file handles to the container, then the destructor will do the actual container traversal to close the files. You have just given an example where RAII will provide a library solution. Look into thread pool implementations. How are the threads in the pool eventually all disposed?

Thomas
No, you'd call the bulk container manually to clos...

No, I'd create a facility to do that, and it would be a RAII enabled facility.

Thomas
Try a language which conventionally uses defer for...

Harder, not impossible. With RAII, its impossible to forget to dispose a resource. A smart pointer guarantees memory disposal. A file class guarantees file closing. A thread pool class will shutdown all threads at destruction. A container will dispose it's memory. A string class will clean up its resources when out of scope. With defer, you have to still specify what clean up routines to call. With RAII, I don't, as long the default works, which is most cases.

Thomas- Автор вопроса
Kenshin Himura
You are still keeping the resources open for longe...

You are still keeping the resources open for longer than necessary. Sometimes you want that, closing can be a performance bottleneck (Windows) that you might want to defer to later

Thomas- Автор вопроса
Kenshin Himura
Harder, not impossible. With RAII, its impossible...

It's not impossible to forget with RAII, you could forget while implementing the destructor

Thomas
They're very familiar with it lol, they're mostly ...

If they really hate RAII, I honestly question their C++ expertise. And if they are "old school", I hope they are not stuck in a mindset of C++ that is closer to C, cause getting stuck in old mindsets and ways happens often. Game environments are usually constrained, which is why they avoid exceptions and use specialized versions of the std library. However, RAII can be used in any environment cause it is an idiom based on a core C++ feature, no matter the environment; guaranteed deterministic local object destruction at end of scope.

Thomas
You are still keeping the resources open for longe...

That is what pool classes are for. I mentioned thread pools in several messages above. Those pool classes will still be RAII classes in C++.

Thomas
It's not impossible to forget with RAII, you could...

Notice the difference between RAII and defer here. With RAII, the error is if the RAII class is not implemented correctly. My original comment that led to this thread mentioned "a proper RAII interface." My use of proper meant implemented correctly. This is the case with the std library and most high quality C++ libraries. It is impossible to forget with such high quality libraries. With defer, it comes down to your memory. And that, coupled with more typing, is an excess cognitive load.

Thomas- Автор вопроса
Kenshin Himura
Notice the difference between RAII and defer here....

In my case I think it's an excess cognitive load to remember destructors when you can't easily see them in the calling code

Thomas
In my case I think it's an excess cognitive load t...

In my case, it's an unnecessary cognitive load to have to remember to clean up resources if the language provides a way to do that behind a clean interface. This was one of the reasons for the fast adoption of Java and C#; not having to think about resource management.

Похожие вопросы

Обсуждают сегодня

а зачем этот вопрос для удаления из чата?
Mёdkinson Medvezhkin
63
Friends, how can I find my Wazirx wallet address?
Silm Silm
31
Всем привет! Подскажите. Я написал приложение на Delphi 10.2 Tokyo под Windows 10. И передо мной стал вопрос о том чтобы сделать это приложение кроссплатформенным (под Linux и...
Дмитрий Завгородний
24
Почему стало ломаться на D11? "739002.86400000' is not a valid timestamp" function IncDateTime(aStamp:TTimeStamp;aKind:TTriggerKind;aInterval:Integer):TDateTime; //aStamp = 2...
Катерина Свиридова
8
How many Cashfusion server now?
Crypto life
22
Кто знает локации, где можно машину красиво отфоткать?
Lalalashechki Lalala
23
Привет всем. Подскажите где можно посмотреть, какая версия электрон, поддерживает версии windows? Некий changelog. Мне бы желательно, поддержку 7,8,10... latest, как понимаю и...
Anonym Squad
21
My 7 year old daughter recognizes the Bitcoin symbol and knows it's currency. What are the top ,3-5 most basic important concepts to convey to a kid about BCH? I started with ...
Big Hair
23
I wonder why they don't buy LTC directly on exchanges but through Grayscale. Does someone know the correct answer? Are the above numbers really correct?
Linda Vu
9
The main vulnerable points of #Monero There is an axiom in computer security that says that a system is as safe as its most vulnerable point. Monero is a #privacy blockchain ...
LiberLion
15
Карта сайта