memory-management

Hoard memory allocator

大城市里の小女人 提交于 2020-01-04 05:12:14
问题 Hoard memory allocator I'm reading papers about Hoard memory allocator, and everything is understandable, but one thing not, how it reduces contention for the heap caused when multiple threads allocate or free memory, after avoids the false sharing that can be introduced by memory allocators and at the same time, it applies strict bounds on fragmentation. How did they achieve it? 回答1: From the paper, Hoard allocates memory internally in superblocks as required by the per-processor heaps .

Why does this struct definition add extra one byte of memory usage?

岁酱吖の 提交于 2020-01-04 03:18:13
问题 #include <stdio.h> typedef struct { short x,y; char type; } Tile; int main(int argc, const char *argv[]) { printf("%d\n",sizeof(short)); printf("%d\n",sizeof(char)); printf("%d\n",sizeof(Tile)); return 0; } The output is: 2 1 6 I expected sizeof(Tile) to be 5, instead of 6. Is this a well-defined behaviour that structs add one extra byte of memory usage, or is it implementation dependant? 回答1: It's because of padding (kind of like rounding). for example: struct example1 { char a; int b; char

Copy or retain NSString parameter?

烂漫一生 提交于 2020-01-04 02:40:08
问题 I'm developing an iOs 4 app with latest SDK and XCode 4.2 I have a question about NSString parameters. This is my class definition: #import <Foundation/Foundation.h> @interface BlogEntry : NSObject { NSString* title; NSString* text; NSDate* date; NSString* photo; } - (id)initWithTitle:(NSString*)titulo text:(NSString*)texto date:(NSDate*)fecha photo:(NSString*)foto; @end And implementation: #import "BlogEntry.h" @implementation BlogEntry - (id)initWithTitle:(NSString*)titulo text:(NSString*

Is malloc faster when I freed memory before

こ雲淡風輕ζ 提交于 2020-01-04 02:09:09
问题 When I allocate and free memory and afterwards I allocate memory that is max the size as the previously freed part. May the 2nd allocation be faster than the first? Maybe because it already knows a memory region that is free? Or because this part of the heap is still assigned to the process? Are there other possible advantages? Or does it generally make no difference? Edit: As asked in the comments: I am especially interested in gcc and MSVC. My assumption was that the memory was not

OpenCl cleanup causes segfault

二次信任 提交于 2020-01-04 02:04:06
问题 I constructed my own little Opencl example using different sources on the net. The actual kernel works, and I get the output I want, but the cleanup functions, I found in one of the examples, cause segfaults. What did I do wrong? #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <CL/cl.h> //opencl #define CL_CHECK(_expr) \ do { \ cl_int _err = _expr; \ if (_err == CL_SUCCESS) \ break; \ fprintf(stderr, "OpenCL Error: '%s' returned %d!\n", #_expr, (int)_err); \ abort(); \ }

Force the JVM to collect garbage early and reduce system memory used early

我只是一个虾纸丫 提交于 2020-01-04 01:56:28
问题 We operate a Java application that we did not develop. This application uses quite a lot of memory for certain tasks, depending on the data, that is manipulated, up to 4GB. At other times, very little memory is needed, around 300MB. Once the JVM grabs hold of a lot of memory, it takes a very long time until the garbage is collected and even longer until memory is returned back to the operating system. That's a problem for us. What happens is as follows: The JVM needs a lot of memory for a

Does Swift's UnsafeMutablePointer<Float>.allocate(…) actually allocate memory?

与世无争的帅哥 提交于 2020-01-03 20:57:18
问题 I'm trying to understand Swift's unsafe pointer API for the purpose of manipulating audio samples. The non-mutable pointer variants (UnsafePointer, UnsafeRawPointer, UnsafeBufferPointer) make sense to me, they are all used to reference previously allocated regions of memory on a read-only basis. There is no type method "allocate" for these variants The mutable variants (UnsafeMutablePointer, UnsafeMutableRawPointer), however, are documented as actually allocating the underlying memory.

Why is my android app using so much memory at startup

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 20:28:14
问题 I have been looking into a memory leak issue for a while. I found a cover flow on the internet from http://www.inter-fuser.com/2010/02/android-coverflow-widget-v2.html Now I was under the impression this app was causing my outofmemory issues, and its still possible that it has something to do with it. However, I have deleted everything from my application except the splash screen. There are no other activities. and it does Nothing...... The initial intent loads the Splash Screen activity. My

System.Drawing and Garbage Collection

帅比萌擦擦* 提交于 2020-01-03 19:11:27
问题 As some may be aware, I recently posted about high memory usage on my website and I have an idea that my thumbnailer may have something to do with this as I am not actively disposing of the instance when it has been used due to my misunderstanding how it works. I am now looking at my code for the thumbnailer and would like some advice on when something would actually need disposing of, is it ONLY when you create a new instance of an object? Like: Target := System.Drawing.Bitmap.Create(Trunc

System.Drawing and Garbage Collection

青春壹個敷衍的年華 提交于 2020-01-03 19:10:06
问题 As some may be aware, I recently posted about high memory usage on my website and I have an idea that my thumbnailer may have something to do with this as I am not actively disposing of the instance when it has been used due to my misunderstanding how it works. I am now looking at my code for the thumbnailer and would like some advice on when something would actually need disposing of, is it ONLY when you create a new instance of an object? Like: Target := System.Drawing.Bitmap.Create(Trunc