allocation

Memset to UnsafeMutablePointer<UInt8> in swift

一曲冷凌霜 提交于 2019-12-10 15:57:32
问题 I have a challenge with a variable with type UnsafeMutablePointer<UInt8> . I have this working code to alloc and set to zero all an UInt8 array in Swift. var bits = UnsafeMutablePointer<UInt8>(calloc(width * height, 8)) The problem is I'd like to do it without use the calloc method. I have this code to alloc the array var bits = UnsafeMutablePointer<UInt8>.alloc(width * height) but I can't find a method to set to zero all the memory. I know I can do this, but I don't think is the best way.

Efficiency of multiplication by 2

天大地大妈咪最大 提交于 2019-12-10 10:59:17
问题 I'm supposed to allocate memory geometrically and set the initial size to 1000. When this is filled, it would expand to 2000, 4000, and so on. My question is: If I set the initial size to multiply of 2, which is 1024, would it be any different in terms of efficiency or any other aspects? Please don't talk about vectors and alternative methods to allocate, this is just theoretical. 回答1: There was an article by Andrew Koenig in a 1998 issue of Journal of Object Orient Programming about buffer

Android Renderscript Allocation.USAGE_SHARED crash

半城伤御伤魂 提交于 2019-12-08 08:25:04
问题 I am getting a crash while running my app which uses renderscript. Unfortunately, the logcat does not give any specific details. b = Bitmap.createBitmap(ib.getWidth(), ib.getHeight(),ib.getConfig()); Allocation mInAllocation = Allocation.createFromBitmap(mRS, inBitmap, Allocation.MipmapControl.MIPMAP_NONE,Allocation.USAGE_SHARED); Allocation mOutAllocation2 = Allocation.createFromBitmap(mRS, outBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SHARED); ...execute an algorithm

c++ dynamic memory allocation limit

与世无争的帅哥 提交于 2019-12-07 16:11:54
问题 Is there any kind of limit, system or otherwise, for dynamic allocation with new or malloc in C++? The system is 64bit and I want to allocate an array of some ~800million structs. Edit: The reason I didn't test it on my own before was because I don't currently have access to a machine with enough memory, so I felt that there was no point testing it on my current machine. After running my own tests, I can allocate 800million elements fine, but malloc returns NULL once I hit ~850million. The

How to copy values from an array into a new one?

房东的猫 提交于 2019-12-07 11:00:54
问题 I've been trying to figure this out off and on for a week now and I keep running into problems. My objective: Write a function that allocates memory for an integer array. The function takes as an argument an integer pointer, the size of the array, and newSize to be allocated. The function returns a pointer to the allocated buffer. When the function is first called, the size will be zero and a new array will be created. If the function is called when the array size is greater than zero, a new

What is “dirty” memory in Instruments?

无人久伴 提交于 2019-12-07 06:46:06
问题 When I monitor my application using instruments and the instrument "allocations" I see a big amount of memory being marked as "dirty". What does that mean? I have no memory leaks in my application yet this pile of "dirty" memory keeps increasing. 回答1: Dirty is a computer term used to denote cached data that needs to be sync'ed with the main memory. Don't worry, since this is automatically done by the hardware. 回答2: "...I am trying to find out what is using up all my memory." The WWDC 2010

How to create a Large Distance Matrix?

孤街醉人 提交于 2019-12-06 16:07:33
How to allocate a huge distance matrix in an appropriate way to avoid " allocation is unable " error. Imagine you have a 100.000 points randomly spreaded over some space. How can one cleverly create a matrix or "dist"-object, which represents the the half of DistMatrix. Maybe it should be another object, which will be able efficiently allocate the large number of distances. You can get the polygonial object from the following link: https://www.dropbox.com/sh/65c3rke0gi4d8pb/LAKJWhwm-l # Load required packages library(sp) library(maptools) library(maps) # Load the polygonal object x <-

Scanning process memory causes crash

无人久伴 提交于 2019-12-06 15:23:09
问题 i have injected my DLL into process and i try to scan memory for addresses with same value as mine, but it results in a crash after i get 1st address , it should be 10 addresses for(DWORD i = MEM_START; i< MEM_END ;i++) { VirtualQuery((void*)i,pMemInfo,sizeof(MEMORY_BASIC_INFORMATION)); if(pMemInfo->AllocationProtect == PAGE_READONLY || PAGE_EXECUTE_WRITECOPY || PAGE_READWRITE || PAGE_WRITECOMBINE) { if(*(DWORD*)i==1337) { addresses.push_back(i); } } } I believe my protection check is wrong

What is considered “small” object in Go regarding stack allocation?

时光毁灭记忆、已成空白 提交于 2019-12-06 13:47:48
问题 The code: func MaxSmallSize() { a := make([]int64, 8191) b := make([]int64, 8192) _ = a _ = b } Then run go build -gcflags='-m' . 2>&1 to check memory allocation details. The result: ./mem.go:10: can inline MaxSmallSize ./mem.go:12: make([]int64, 8192) escapes to heap ./mem.go:11: MaxSmallSize make([]int64, 8191) does not escape My question is why a is small object and b is large object? make 64KB will escape to heap and less will allocate in stack. Does the _MaxSmallSize = 32 << 10 is the

opencv cv::mat allocation

混江龙づ霸主 提交于 2019-12-06 07:59:25
问题 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