resource-management

What wrapper class in C++ should I use for automated resource management?

删除回忆录丶 提交于 2019-12-29 05:50:13
问题 I'm a C++ amateur. I'm writing some Win32 API code and there are handles and weirdly compositely allocated objects aplenty. So I was wondering - is there some wrapper class that would make resource management easier? For example, when I want to load some data I open a file with CreateFile() and get a HANDLE . When I'm done with it, I should call CloseHandle() on it. But for any reasonably complex loading function there will be dozens of possible exit points, not to mention exceptions. So it

Why is use better than using?

故事扮演 提交于 2019-12-22 01:37:42
问题 According to the last sentence on this MSDN page use is to be preferred over using . I've heard it elsewhere (this answer, for example). Why is this? I realize use was added later. But what's the difference? On the surface, using seems more useful because you can control when Dispose() is called, and you can explicitly ignore the bound value (e.g., (fun _ -> ...) ) if needed. 回答1: I think that the reason for preferring use is just that the syntax is simpler. Many other language constructs

C++ Correct way to free a vector of a custom class

孤街浪徒 提交于 2019-12-20 06:16:26
问题 I have my custom class, like: class MyClass { public: int i; std:string name; void DoSomeStuff(); } and another class with a list of my custom class: class MyClassList { public: std::vector<MyClasss> myClassList; } How shall be the list destructor in order to release all used vector space in memory: MyClassList::~MyClassList { myClassList.clear(); delete &myClassList; } Is that code right, redundant or wrong ? Thanks for helping... 回答1: You don't need to do anything, just let it fall out of

What Automatic Resource Management alternatives exist for Scala?

倾然丶 夕夏残阳落幕 提交于 2019-12-17 10:14:18
问题 I have seen many examples of ARM (automatic resource management) on the web for Scala. It seems to be a rite-of-passage to write one, though most look pretty much like one another. I did see a pretty cool example using continuations, though. At any rate, a lot of that code has flaws of one type or another, so I figured it would be a good idea to have a reference here on Stack Overflow, where we can vote up the most correct and appropriate versions. 回答1: For now Scala 2.13 has finally

HttpContext.GetGlobalResourceObject always returns null

和自甴很熟 提交于 2019-12-07 12:03:38
问题 I created two files in the App_GlobalResources folder: SiteResources.en-US.resx SiteResources.sp-SP.resx Both contain a value for "SiteTitleSeparator". Here is what I am trying to do (The following line always returns null): string sep = (string)GetGlobalResourceObject("SiteResources", "SiteTitle"); Note, that the Culture property on the page is set. Answers in both VB and C# will be welcomed. 回答1: I changed the name of SiteResources.en-US.resx to SiteResources.resx and now everything works

What happens if delete[] p fails?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 16:22:24
问题 Suppose I have a pointer to a dynamically allocated array of 10 elements: T* p = new T[10]; Later, I want to release that array: delete[] p; What happens if one of the T destructors throws an exception? Do the other elements still get destructed? Will the memory be released? Will the exception be propagated, or will program execution be terminated? Similarly, what happens when a std::vector<T> is destroyed and one of the T destructors throws? 回答1: I can not see it explicitly called out in the

What happens if delete[] p fails?

我是研究僧i 提交于 2019-12-03 04:48:31
Suppose I have a pointer to a dynamically allocated array of 10 elements: T* p = new T[10]; Later, I want to release that array: delete[] p; What happens if one of the T destructors throws an exception? Do the other elements still get destructed? Will the memory be released? Will the exception be propagated, or will program execution be terminated? Similarly, what happens when a std::vector<T> is destroyed and one of the T destructors throws? Martin York I can not see it explicitly called out in the standard: Just that they will be called in reverse order of creation 5.3.5 Delete [expr.delete]

Is it possible to prevent DoSing on Google App Engine?

允我心安 提交于 2019-12-03 03:18:07
问题 I'm considering developing an app for Google App Engine, which should not get too much traffic. I'd really rather not pay to exceed the free quotas. However, it seems like it would be quite easy to cause a denial of service attack by overloading the app and exceeding the quotas. Are there any methods to prevent or make it harder to exceed the free quotas? I know I could, for example, limit the number of requests from an IP (making it harder to exceed the CPU quota), but is there any way to

Is it possible to prevent DoSing on Google App Engine?

只愿长相守 提交于 2019-12-02 16:48:28
I'm considering developing an app for Google App Engine, which should not get too much traffic. I'd really rather not pay to exceed the free quotas. However, it seems like it would be quite easy to cause a denial of service attack by overloading the app and exceeding the quotas. Are there any methods to prevent or make it harder to exceed the free quotas? I know I could, for example, limit the number of requests from an IP (making it harder to exceed the CPU quota), but is there any way to make it harder to exceed the requests or bandwidth quotas? There are no built-in tools to prevent DoS. If

C++ Correct way to free a vector of a custom class

痴心易碎 提交于 2019-12-02 11:54:43
I have my custom class, like: class MyClass { public: int i; std:string name; void DoSomeStuff(); } and another class with a list of my custom class: class MyClassList { public: std::vector<MyClasss> myClassList; } How shall be the list destructor in order to release all used vector space in memory: MyClassList::~MyClassList { myClassList.clear(); delete &myClassList; } Is that code right, redundant or wrong ? Thanks for helping... You don't need to do anything, just let it fall out of scope. RAII will ensure that the vector memory is cleaned up when your instance of MyClassList falls out of