allocation

Android: Track number of objects created

匆匆过客 提交于 2019-12-04 17:54:04
问题 I'm porting a game to Android (there's a lot of code and very little of it is mine), and DalvikVM is telling me (through LogCat) all about the garbage collection. At some point in the code, I get a stream of "GC freed x objects / x ms" messages, basically informing me that ~150,000 objects have just been deleted and it's taking a full second. I want to know where these came from! I am pretty sure I'm not creating that many objects intentionally. So, is there a way to get... basically the

opencv cv::mat allocation

我们两清 提交于 2019-12-04 16:24:39
Hello I have a basic question about opencv. If I try to allocate memory with the cv::Mat class I could do the following: cv::Mat sumimg(rows,cols,CV_32F,0); float* sumimgrowptr = sumimg.ptr<float>(0); but then I get a bad pointer (Null) back. In the internet some person use this: cv::Mat* ptrsumimg = new cv::Mat(rows,cols,CV_32F,0); float* sumimgrowptr = ptrsumimg->ptr<float>(0); and also here I get a Null pointer back ! but If I finally do this : cv::Mat sumimg; sumimg.create(rows,cols,CV_32F); sumimg.setTo(0); float* sumimgrowptr = sumimg.ptr<float>(0); then everything is fine ! so I wannted

Runtime vs compile time memory allocation in java

被刻印的时光 ゝ 提交于 2019-12-04 10:52:20
I am confused regarding whether memory allocation in java occurs at run time or compile time. For example: class Test{ int a; public Test(){ a=10; } }; // somewhere else Test t = new Test(); Is a allocated at run time or at compile time? If at compile time, how is it possible as java runs on a VM which directly takes compiled .class files? Also: when is a assigned the value 10 ? how does it work for reference variable t ? Thanks. Compile time no memory allocation happens. Only at load and runtime. Compile time generates .class files that's it. Remember you need to have a main class to run the

Does STL Vector use 'new' and 'delete' for memory allocation by default?

北城以北 提交于 2019-12-04 10:40:27
问题 I am working on a plugin for an application, where the memory should be allocated by the Application and keep track of it. Hence, memory handles should be obtained from the host application in the form of buffers and later on give them back to the application. Now, I am planning on using STL Vectors and I am wondering what sort of memory allocation does it use internally. Does it use 'new' and 'delete' functions internally? If so, can I just overload 'new' and 'delete' with my own functions?

linux high kernel cpu usage on memory initialization

柔情痞子 提交于 2019-12-04 09:33:44
问题 I have a problem with high CPU cunsumption by the linux kernel, while bootstrapping my java applications on server. This problem occurs only in production, on dev servers everything is light-speed. upd9: There was two question about this issue: How to fix it? - Nominal Animal suggested to sync and drop everything, and it really helps. sudo sh -c 'sync ; echo 3 > /proc/sys/vm/drop_caches ; Works. upd12: But indeed sync is enough. Why this happening? - It is still open for me, I do understand

To “new” or not to “new”

∥☆過路亽.° 提交于 2019-12-04 07:48:25
Is there a rule of thumb to follow when to use the new keyword and when not to when declaring objects? List<MyCustomClass> listCustClass = GetList(); OR List<MyCustomClass> listCustClass = new List<MyCustomClass>(); listCustClass = GetList(); In your scenario it seems that the actual creation of the object is being performed inside your GetList() method. So your first sample would be the correct usage. When created, your List<MyCustomClass> is stored in the heap, and your listCustClass is simply a reference to that new object. When you set listCustClass to GetList() the reference pointer of

C++ gcc extension for non-zero-based array pointer allocation?

大憨熊 提交于 2019-12-04 07:01:04
问题 I am looking for a gcc-supported C++ language extension to enable the allocation of non-zero-based array pointers. Ideally I could simply write: #include<iostream> using namespace std; // Allocate elements array[lo..hi-1], and return the new array. template<typename Elem> Elem* Create_Array(int lo, int hi) { return new Elem[hi-lo] - lo; // FIXME what about [expr.add]/4. // How do we create a pointer outside the array bounds? } // Deallocate an array previously allocated via Create_Array.

Using parse.com and having allocation memory issue

假如想象 提交于 2019-12-04 06:34:54
问题 I'm new to programming, I've been making an app for the last 3 months and learned a few things. But I haven't come across to how to solve this issue. I've been using Parse.com as my server, sending pictures, saving user data etc. With all of this data the app keeps crashing if I open some activities more than a few times, particularly activities with pictures. Now I have compressed the pictures and made them max 400x400 in resolution. But somehow the allocation is out of memory keeps popping

Are the members of a heap allocated class automatically allocated in the heap?

三世轮回 提交于 2019-12-04 04:46:26
问题 Let's say I have: class A{ public: int x; int y; }; And I allocate an A instance like: A *a = new A(); Does a.x and a.y are also allocated in the heap, since they are 'dependent' of a heap allocated object? Thank you. 回答1: It is important to understand that C++ uses "copy semantic". This means that variables and structure fields do not contain references to values, but the values themselves. When you declare struct A { int x; double yarr[20]; }; each A you will create will contain an integer

Alignment restrictions for malloc()/free()

坚强是说给别人听的谎言 提交于 2019-12-04 04:24:44
Older K&R (2nd ed.) and other C-language texts I have read that discuss the implementation of a dynamic memory allocator in the style of malloc() and free() usually also mention, in passing, something about data type alignment restrictions. Apparently certain computer hardware architectures (CPU, registers, and memory access) restrict how you can store and address certain value types. For example, there may be a requirement that a 4 byte ( long ) integer must be stored beginning at addresses that are multiples of four. What restrictions, if any, do major platforms (Intel & AMD, SPARC, Alpha)