memory-management

How is Stack memory allocated when using 'push' or 'sub' x86 instructions?

半城伤御伤魂 提交于 2020-01-11 11:08:10
问题 I have been browsing for a while and I am trying to understand how memory is allocated to the stack when doing for example: push rax Or moving the stack pointer to allocate space for local variables of a subroutine: sub rsp, X ;Move stack pointer down by X bytes What I understand is that the stack segment is anonymous in the virtual memory space,i.e., not file backed. What I also understand is that the kernel will not actually map an anonymous virtual memory segment to physical memory until

java efficiency comparison in terms of memory allocation

↘锁芯ラ 提交于 2020-01-11 10:49:11
问题 This may be a duplicate question but I couldnt find what I am searching. If it exists, sorry about duplication. I want to learn that if the following part of codes are same in terms of memory allocation. //first int n = some_number; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ int a = something; } } //second int i, j, a; for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ a = something; } } I wonder, if java allocates the variable a n^2 times and j n times in the first code or both are

java efficiency comparison in terms of memory allocation

我只是一个虾纸丫 提交于 2020-01-11 10:49:06
问题 This may be a duplicate question but I couldnt find what I am searching. If it exists, sorry about duplication. I want to learn that if the following part of codes are same in terms of memory allocation. //first int n = some_number; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ int a = something; } } //second int i, j, a; for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ a = something; } } I wonder, if java allocates the variable a n^2 times and j n times in the first code or both are

Does C# method take memory?

南笙酒味 提交于 2020-01-11 09:52:17
问题 What happens in memory when there is a class with 50 methods and we create 50 object instances of that class? What is the best solution for having an object with a lot of functionality and less memory usage? 回答1: Yes, C#/.Net methods require memory on per-AppDomain basis, there is no per-instance cost of the methods/properties. Cost comes from: methods metadata (part of type) and IL. I'm not sure how long IL stays loaded as it really only needed to JIT so my guess it is loaded as needed and

Does C# method take memory?

≡放荡痞女 提交于 2020-01-11 09:50:07
问题 What happens in memory when there is a class with 50 methods and we create 50 object instances of that class? What is the best solution for having an object with a lot of functionality and less memory usage? 回答1: Yes, C#/.Net methods require memory on per-AppDomain basis, there is no per-instance cost of the methods/properties. Cost comes from: methods metadata (part of type) and IL. I'm not sure how long IL stays loaded as it really only needed to JIT so my guess it is loaded as needed and

Memory continuously increase then app crash when i display image from document directory during scrolling UITableview

泄露秘密 提交于 2020-01-11 09:33:09
问题 My Requirement is download all images in application memory and display it from local if its available. Below is my code to access image from local and if its not available then it will download then display. [cell.imgProfilePic processImageDataWithURLString:cData.PICTURE]; I have made custom UIImageView class DImageView.h #import <UIKit/UIKit.h> @interface DImageView : UIImageView @property (nonatomic, strong) UIActivityIndicatorView *activityView; - (void)processImageDataWithURLString:

Allocate a string array from inside a function in C

天涯浪子 提交于 2020-01-11 09:19:45
问题 I have a function that scans a file and returns the number of the lines along with the lines in a string array, my function looks like this : int load_lines(char* _file, char** _array){ FILE *infile; char line_buffer[BUFSIZ]; char line_number; infile = fopen(_file, "r"); ine_number = 0; while (fgets(line_buffer, sizeof(line_buffer), infile)) ++line_number; fclose(infile); _array = malloc (line_number * sizeof(char*)); infile = fopen(_file, "r"); line_number = 0; while (fgets(line_buffer,

C++: Measuring memory usage from within the program, Windows and Linux [duplicate]

流过昼夜 提交于 2020-01-11 07:36:27
问题 This question already has answers here : How to determine CPU and memory consumption from inside a process? (9 answers) Closed 2 years ago . See, I wanted to measure memory usage of my C++ program. From inside the program, without profilers or process viewers, etc. Why from inside the program? Measurements will be done thousands of times—must be automated; therefore, having an eye on Task Manager , top , whatever, will not do Measurements are to be done during production runs —performance

Memory leak: steady increase in memory usage with simple device motion logging

不问归期 提交于 2020-01-11 06:52:25
问题 Consider this simple Swift code that logs device motion data to a CSV file on disk. let motionManager = CMMotionManager() var handle: NSFileHandle? = nil override func viewDidLoad() { super.viewDidLoad() let documents = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString let file = documents.stringByAppendingPathComponent("/data.csv") NSFileManager.defaultManager().createFileAtPath(file, contents: nil, attributes: nil) handle = NSFileHandle

Out of memory exception while loading images

雨燕双飞 提交于 2020-01-11 06:29:09
问题 I am using the following piece of code to load images as thumbnails to a FlowLayoutPanel control. Unfortunately i get an OutOfMemory exception. As you already guess the memory leak is found at line Pedit.Image = System.Drawing.Image.FromStream(fs) So how could i optimize the following code? Private Sub LoadImagesCommon(ByVal FlowPanel As FlowLayoutPanel, ByVal fi As FileInfo) Pedit = New DevExpress.XtraEditors.PictureEdit Pedit.Width = txtIconsWidth.EditValue Pedit.Height = Pedit.Width / (4 /