memory-management

When is memory allocated during instance creating or using new keyword for object creation?

橙三吉。 提交于 2020-01-03 02:23:08
问题 As I read somewhere, memory is allocated when instances are created and a space is allocated from the heap. If it is right than when and how much exactly memory is allocated during instances and objects creation? 回答1: Variables declared within a method are stored within the stack, while the actual objects are stored on the heap. Consider Integer a = new Integer(10); In this example, an object of type Integer is created on the heap and a reference (either 32 or 64bits) is returned and stored

Python process keeps growing in django db upload script

≯℡__Kan透↙ 提交于 2020-01-03 01:28:07
问题 I'm running a conversion script that commits large amounts of data to a db using Django's ORM. I use manual commit to speed up the process. I have hundreds of files to to commit, each file will create more than a million objects. I'm using Windows 7 64bit. I noticed the Python process keeps growing until it consumes more than 800MB, and this is only for the first file! The script loops over records in a text file, reusing the same variables and without accumulating any lists or tuples. I read

Core Data: Memory not released after manually faulting managed objects

孤人 提交于 2020-01-03 01:22:45
问题 I am using the following code to retrieve the maximum value of an attribute on Core Data - (NSDate*)latestDateForLocalEntity:(NSString*)entityString key:(NSString*)key inManagedObjectContext:(NSManagedObjectContext*)context { NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityString]; NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:key ascending:YES]; request.sortDescriptors = @[sortDescriptor]; NSError *localError; NSArray *localResults =

Using custom allocator for AllocatorAwareContainer data members of a class

流过昼夜 提交于 2020-01-03 00:39:12
问题 Given a non-stateless custom allocator A (say, arena allocator, binded to some contiguous memory chunk of runtime-known size) and class S , containing a fileds of AllocatorAwareContainer types: struct S { A() = default; // another c-tors std::vector< T > v; std::shared_ptr< U > s; }; I want to use A for a subset (or even for all) AllocatorAwareContainer fields of class S . It is clear, that I should to provide one another template parameter for class S and change types of all the interesting

Using custom allocator for AllocatorAwareContainer data members of a class

坚强是说给别人听的谎言 提交于 2020-01-03 00:39:08
问题 Given a non-stateless custom allocator A (say, arena allocator, binded to some contiguous memory chunk of runtime-known size) and class S , containing a fileds of AllocatorAwareContainer types: struct S { A() = default; // another c-tors std::vector< T > v; std::shared_ptr< U > s; }; I want to use A for a subset (or even for all) AllocatorAwareContainer fields of class S . It is clear, that I should to provide one another template parameter for class S and change types of all the interesting

Lists double their space in c# when they need more room. At some point does it become less efficient to double say 1024 to 2048?

非 Y 不嫁゛ 提交于 2020-01-02 23:11:06
问题 When numbers are smaller, it's quick to grow the size of an array list from 2 to 4 memory addresses but when it starts to increase the amount of space closer to the max amount of space allowed in an array list (close to the 2MB limit). Would changing how much space is allotted in those bigger areas be more efficient if it was only growing the size of the array by a fraction of the size it needs at some point? Obviously growing the size from 1mb to 2mb isn't really a big deal now-days HOWEVER,

C++ dynamically allocated array of statically dimensioned arrays

自作多情 提交于 2020-01-02 15:48:03
问题 I need to create a structure that holds a variable number of 'char[2]'s, i.e. static arrays of 2 chars. My question is, how do I allocate memory for x number of char[2]. I tried this (assuming int x is defined): char** m = NULL; m = new char[x][2]; ... delete [] m; (it didn't work) I realise I could use std::vector<char[2]> as a container, but I'm curious as to how it would be done with raw pointers. I am very new to C++ and trying to learn. 回答1: In your code, the type of 'm' doesn't match

C++ dynamically allocated array of statically dimensioned arrays

不羁岁月 提交于 2020-01-02 15:47:30
问题 I need to create a structure that holds a variable number of 'char[2]'s, i.e. static arrays of 2 chars. My question is, how do I allocate memory for x number of char[2]. I tried this (assuming int x is defined): char** m = NULL; m = new char[x][2]; ... delete [] m; (it didn't work) I realise I could use std::vector<char[2]> as a container, but I'm curious as to how it would be done with raw pointers. I am very new to C++ and trying to learn. 回答1: In your code, the type of 'm' doesn't match

List<T> and ArrayList default capacity

a 夏天 提交于 2020-01-02 15:00:16
问题 I have been looking at .NET's List and ArrayList implementations with Reflector. When looking at the Add(T item) I ran across this. EnsureCapacity (this._size + 1): public void Add(T item) { if (this._size == this._items.Length) { this.EnsureCapacity(this._size + 1); } this._items[this._size++] = item; this._version++; } So EnsureCapacity looks like this: private void EnsureCapacity(int min) { if (this._items.Length < min) { int num = (this._items.Length == 0) ? 4 : (this._items.Length * 2);

Does Scripting.Dictionary's RemoveAll() method release all of its elements first?

Deadly 提交于 2020-01-02 13:47:59
问题 In a VB6 application, I have a Dictionary whose keys are String s and values are instances of a custom class. If I call RemoveAll() on the Dictionary , will it first free the custom objects? Or do I explicitly need to do this myself? Dim d as Scripting.Dictionary d("a") = New clsCustom d("b") = New clsCustom ' Are these two lines necessary? Set d("a") = Nothing Set d("b") = Nothing d.RemoveAll 回答1: Yes, all objects in the Dictionary will be released after a call to RemoveAll() . From a