memory-management

Adding `int` to address causes int to be added 4 times

和自甴很熟 提交于 2019-12-25 00:38:01
问题 For a course about the functioning of operating systems, we had to write a malloc/free implementation for a specific sized struct. Our idea was to store the overhead, like the start and end of the specified (static) memory block our code has to work in, in the first few addresses of that block. However, something went wrong with the calculation of the last memory slot; We're adding the size of all usable memory slots to the address of the first usable memory slot, to determine what the last

class overloaded new and delete vs placement new with a bespoke memory class

我怕爱的太早我们不能终老 提交于 2019-12-25 00:27:19
问题 I am investigating the pros and cons between using class overloaded news and deletes vs placement news. By this I mean, either declaring every class I may wish to new and delete with their own operator overloads, or by using the memory manager to give me the memory I need via placement new. I have a memory manager that allows me to allocate memory from a number of pools: enum MemPool { kPool1, kPool2, } class MemoryManager { public: template <typename T> void* Allocate(MemPool pool); void

Objective C - Memory Management Question?

天大地大妈咪最大 提交于 2019-12-24 23:00:23
问题 I know that when setting a retained property to an allocated object it increments the retain count of the object so i need to release it (3rd line, first block of code) But what if i don't have a property, and I am assigning an allocated object to an instant variable. Do i still need to release it????? (3rd line, second block of code) @property (nonatomic, retain) MyObject *myObject; MyObject *obj = [[MyObject alloc] init]; self.myObject = obj; [obj release]; MyObject *myObject; MyObject *obj

Memory management with changing rootViewController of window

空扰寡人 提交于 2019-12-24 22:35:24
问题 I am changing rootViewController of window dynamically in my application in Non - ARC application. My question is do i need to release previously assigned rootViewController? How memory is management is done with previously allocated rootViewController? My Second question is about newrootViewController. how i can manage memory for new rootViewController for window. Any help will be appreciated.... 回答1: Jason is right in his comment above, in reality there are very few reasons not to use ARC.

Implementing a search() method to handle optional case sensitivity [duplicate]

二次信任 提交于 2019-12-24 21:42:06
问题 This question already has answers here : Return local String as a slice (&str) (3 answers) How do I pass modified string parameters? (2 answers) Closed last year . In The Rust Programming Language , there is a chapter which implements a minigrep. Instead of implementing a second search_case_insensitive() method, I wanted to implement a single API which would duplicate code. That attempt went something like this: pub fn search<'a>(query: &str, lines: &'a str, case_insensitive: bool) -> Vec<&'a

NSStatusItem releases icon

落花浮王杯 提交于 2019-12-24 20:22:37
问题 I have an ARC project involving a custom view that appears after clicking a status bar icon. I'm new to programming, so I pulled this example project from GitHub to get up and running. The app runs fine, the only issue is with the status bar item. I set up the NSStatusItem as I should, but as soon as I call setView, the icon seems to be released. I can click an empty space in the menubar which opens the app so the item is there, it's just that the icon is missing. (Image is confirmed to be

Load ELF binary around an arbitrary initialized memory block

孤街醉人 提交于 2019-12-24 20:07:04
问题 I'm working on a project that will require me to load some data into memory at memory addresses determined at runtime and then load an ELF binary into the same address space. I know I can compile the ELF as position-independent, but how can I allocate my memory block and then load and run the binary without overwriting the memory block or moving into a different address space? 回答1: Exec replaces the entire memory space and I don't think there's much you can do about that. But maybe you could

Package Memory Management

天大地大妈咪最大 提交于 2019-12-24 19:55:45
问题 Since I have been running in a lot of difficulties when trying to use DLLs, I decided to try out runtime packages (mainly to avoid the memory manager and type registry problems). From my application I do something like this: HandleList := TList <THandle>.Create; try PackageObj.DoSomething (HandleList); finally FreeAndNil (HandleList); end; The method (inside the runtime package) just adds something to the list: procedure TPackageObject.DoSomething (HandleList: TList <THandle>); begin

Using delete on pointer to std::list?

你。 提交于 2019-12-24 19:28:01
问题 In my program I have a pointer to a std::list object, it is allocated like so. d_list_p = new std::list<some_type*>(); Then later in my program I delete it like so. d_list_p->clear(); delete d_list_p; For some reason I'm getting a Windows breakpoint triggered on the delete statement. If I break at the delete statement I see that the list exists and has a size of 0. Also, I never add an element to the list for the case that throws an error (I think). The code is being compiled with the MS VC++

Activity calling finish in onPause crashes during orientation change

 ̄綄美尐妖づ 提交于 2019-12-24 18:23:19
问题 To preserve resources and prevent memory leaks, I am calling finish() in onPause event whenever app is going from one activity to another. I think it works fine, but when i try to rotate screen, app is crashing - error is "Duplicate finish request" How I can prevent this, is there way in onPause event to detect if app is going to the next activity or just changing orientation? Is there better method for preserving memory then using finish? Thanks for help! 回答1: Just a shot in the dark here,