memory-management

WPF with GDI Memory growth

眉间皱痕 提交于 2019-12-24 08:48:43
问题 I'm writing an app in WPF (C#) that plots certain types of fractals. The data sets are 3d points and need to represented as single pixels. The user can click and drag to rotate the plots The amount of points varies but can be quite large (five million plots or more). Currently I am drawing onto a System.Drawing.Bitmap using a Graphics object then setting a WPF Image's Source property to that bitmap. The problem I have is that when i repeatedly redraw the image memory consumption steadily

How to efficiently allocate space for vector of pointers to virtual base class in modern C++

依然范特西╮ 提交于 2019-12-24 08:30:36
问题 I have following data model struct Base { int x_; int y_; int z_; virtual int getId() const; virtual int getValue() const = 0; virtual Base* create() const = 0; bool operator<(const Base &other); }; struct Derived0 : public Base { virtual Derived0* create() const { return new Derived0(); }; virtual int getId() const; virtual int getValue() const; }; //... struct DerivedN : public Base { virtual DerivedN* create() const { return new DerivedN(); }; virtual int getId() const; virtual int

Would such assignment of image cause a memory leak?

做~自己de王妃 提交于 2019-12-24 08:23:45
问题 - (void)viewDidLoad { [super viewDidLoad]; landscape.image = [UIImage imageNamed:@"tenerife1.png"]; } I assign a new UIImage to the image property of an UIImageView object. I am not sure if that would result in a memory leak? 回答1: No, it should not. The old image should be automatically released when you set the new one, and the "imageNamed" method uses autorelease, so you should be OK there. 回答2: hey take into account imageNamed has serious memory issues as you loose control over its cache -

C - Build dynamically allocated array of pointers to structures filled with input from file

ⅰ亾dé卋堺 提交于 2019-12-24 07:58:09
问题 I need to build an array of pointers to dynamically allocated structures (DBrecord) and fill that array with input from another file. Not sure how to approach this. The data file will have the number of entries first, followed by entries in a specific order. numOfEntries lastName firstName studentID year gpa expGradYear example: 1 Doe John 12345678 senior 3.14159 2015 Here's the code I have so far: class.h typedef enum {firstYear, sophomore, junior, senior, grad} class; main.c #include <stdio

What if accessing a non-existing physical address in X86 system?

拜拜、爱过 提交于 2019-12-24 07:48:36
问题 I am working on a Linux kernel module, which maps a physical address range to a process virtual address space, by playing with process's page tables. Then, I have a question in my head, what will happen if a PTE points to a non-existing physical address? For example, my X86 laptop has 8GB DRAM, and if a PTE has the value of 0x8000000400001227, will the CPU generate some exception for this invalid address accessing? I did a quick a test with that, but there is NOthing unusual happened, and I

Calloc inside function

让人想犯罪 __ 提交于 2019-12-24 07:47:38
问题 Looking at this question that has just been asked: Inconveniences of pointers to static variables would doing something like this be considered bad practice, then? char* strpart(char* string, int start, int count) { char* strtemp; int i = 0; int j = 0; int strL = strlen(string); if ( count == 0 ) { count = strL; } strtemp = (char*) calloc((count + 1), sizeof(char)); for ( i = start; i < (start+count); i++ ) { strtemp[j] = string[i]; j++; } return strtemp; } Sorry it's written quickly, but the

Is it possible to get the size of the type that a pointer points to in Delphi 7?

不打扰是莪最后的温柔 提交于 2019-12-24 07:43:04
问题 I want to get the size of any "record" type in following function. But seems it doesn't work: function GetDataSize(P : Pointer) : Integer; begin Result := SizeOf(P^); // **How to write the code?** end; For example, the size of following record is 8 bytes SampleRecord = record Age1 : Integer; Age2 : Integer; end; But GetDataSize(@a) always returns 1 (a is a variable of SampleRecord type of course). What should I do? I noticed that Delphi has a procedure procedure New(var P: Pointer) which can

CGContextDrawPDFPage crashing without ever producing a memory warning

╄→尐↘猪︶ㄣ 提交于 2019-12-24 07:39:29
问题 I'm trying to render a PDF page with some annotations on it (to email), and most of the time this works fine. However, with this PDF in particular it seems to crash every time on the call to CGContextDrawPDFPage for the first page. I have added CGContextSetInterpolationQuality(context, kCGInterpolationHigh); CGContextSetRenderingIntent(context, kCGRenderingIntentDefault); as a recommendation from CGContextDrawPDFPage taking up large amounts of memory but that did not seem to solve my issue. I

why warning with my performSelector

前提是你 提交于 2019-12-24 07:37:17
问题 Below is a simple PerformSelector that sends a message to obj to perform the looping method. All works well but I get the following yellow warning. PerformSelector may cause a leak because its selector is unknown. #import "MyClass.h" #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { MyClass *obj = [[MyClass alloc]init]; SEL mySel = @selector(looping); [obj performSelector:mySel]; } return 0; } This warning does not make sense because the

Insert a value changing shape in allocated vector fortran

大城市里の小女人 提交于 2019-12-24 07:26:05
问题 I would like to ask you about a problem that I have frequently in the management of CSR/CSC* matrices using Fortran. Suppose we have a vector V with N real values. The vector has been allocated previously with a certain size. Now we have to add a value in the middle of it at the index P. A brute force code would be: allocate(tempV(N)) tempV=V deallocate(V) allocate(V(N+1)) V=(/tempV(1:P-1), newValue, tempV(P:N)/) deallocate(tempV) Clearly, if it is done once it is not a problem, but repeating