memory-management

How do I force a program to appear to run out of memory?

我怕爱的太早我们不能终老 提交于 2019-12-29 16:26:10
问题 I have a C/C++ program that might be hanging when it runs out of memory. We discovered this by running many copies at the same time. I want to debug the program without completely destroying performance on the development machine. Is there a way to limit the memory available so that a new or malloc will return a NULL pointer after, say, 500K of memory has been requested? 回答1: Try turning the question on its head and asking how to limit the amount of memory an OS will allow your process to use

Allocate memory for 2D array with C++ new[]

对着背影说爱祢 提交于 2019-12-29 09:17:08
问题 When I read some values from the user and I need to create an array of the specific size I do it somehow like this: #include <iostream> using namespace std; unsigned* numbers; int main() { int a; cin >> a; numbers = new unsigned[a]; } How can I do it with a 2d array(sized a*b read from the user)? 回答1: Anything that would look like a 2D-Array in code will not be a physical 2D array in memory, but either one plain block of memory or scattered, depending on how you allocate it. You can torture

How to column bind two ffdf

一个人想着一个人 提交于 2019-12-29 09:16:05
问题 Suppose two ffdf files: library(ff) ff1 <- as.ffdf(data.frame(matrix(rnorm(10*10),ncol=10))) ff2 <- ff1 colnames(ff2) <- 1:10 How can I column bind these without loading them into memory? cbind doesn't work. There is the same question http://stackoverflow.com/questions/18355686/columnbind-ff-data-frames-in-r but it does not have an MWE and the author abandoned it so I reposted. 回答1: You can use the following construct cbind.ffdf2 , making sure the column names of the two input ffdf 's are not

Limiting java application's memory and cpu usage

匆匆过客 提交于 2019-12-29 08:32:20
问题 Say, "run myApp.jar with cpu=800 and memory=1024" Ive been doing java programming for many years and it is an embarrasment to ask this question. I don't even know whether this is possible or not. And if so, how? What I just want know is if it is possible to set a java program's maximum memory and cpu usage. I suddenly thought of this because of I recently started developing mobile apps. I want to know how the app will behave on the device which has very limited memory and processor. I saw

Limiting java application's memory and cpu usage

≯℡__Kan透↙ 提交于 2019-12-29 08:32:10
问题 Say, "run myApp.jar with cpu=800 and memory=1024" Ive been doing java programming for many years and it is an embarrasment to ask this question. I don't even know whether this is possible or not. And if so, how? What I just want know is if it is possible to set a java program's maximum memory and cpu usage. I suddenly thought of this because of I recently started developing mobile apps. I want to know how the app will behave on the device which has very limited memory and processor. I saw

Help debugging iPhone app - EXC_BAD_ACCESS

时间秒杀一切 提交于 2019-12-29 08:08:12
问题 I've developed my application using my 3G device to test with. Upon giving this to a friend to test, he's noticed that it crashes..I've had a look at the crash log, but it's not much use except for the "EXC_BAD_ACCESS" statement after a few memory warnings. On my device, I can use the imagePicker lots, and each time a photo is taken I get a memory warning, but this doesn't cause any problems. On my friend's device (also a 3G), after a couple of images chosen from the camera, the app crashes.

Implementing a std::vector like container without undefined behavior

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-29 08:07:55
问题 It may surprise some coders and, as surprising as it can be, it is not possible to implement std::vector without non-standard support of the compilers. The problem essentially resides on the ability to perform pointer arithmetic on a raw storage region. The paper, p0593: Implicit creation of objects for low-level object manipulation, that appears in @ShafikYaghmour answer, exposes clearly the problematic and proposes modification of the standard in order to make implementation of vector like

How to minimize the costs for allocating and initializing an NSDateFormatter?

纵然是瞬间 提交于 2019-12-29 07:37:06
问题 I noticed that using an NSDateFormatter can be quite costly. I figured out that allocating and initializing the object already consumes a lot of time. Further, it seems that using an NSDateFormatter in multiple threads increases the costs. Can there be a blocking where the threads have to wait for each other? I created a small test application to illustrate the problem. Please check it out. http://github.com/johnjohndoe/TestNSDateFormatter git://github.com/johnjohndoe/TestNSDateFormatter.git

How to find how much space is allocated by a call to malloc()?

限于喜欢 提交于 2019-12-29 07:35:09
问题 I'm trying to write a size function like this: size(void *p,int size); Which would return the size of an array which is pointed to by p. For example: Int *a = malloc((sizeof(int)*100)); size(a,sizeof(int)); // this should return 100 I think this is possible because if I recall, malloc keeps track of the space allocated in some header bytes. Here's what I have so far: int size(void *p, int size) { p = (unsigned int *)p - 1; unsigned int elements = (*(unsigned int *)p); return elements/size; }

Custom memory alloc and dealloc which multiple Inheritance class

人走茶凉 提交于 2019-12-29 06:44:17
问题 i want do memory management in my project. i do not want operator global new/delete so i implement a simple memory alloctor. this is my code: class IAllocator { public: void* Alloc( unsigned int size ) { 1. alloc memory. 2. trace alloc. } void Dealloc( void* ptr ) { 1. free memory. 2. erase trace info. } template< typename T > void Destructor( T* ptr ) { if ( ptr ) ptr->~T(); } }; // macro for use easy. # define MYNEW( T ) new ( g_Allocator->Alloc( sizeof( T ) ) ) T # define MYDEL( ptr ) if