memory-management

What is the difference between static const char * const and static const char []? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-24 07:05:58
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: What is the difference between char a[] = “string”; and char *p = “string”; Will the array version allocate the array memory, so a 100 byte string will use 100 bytes on the constant section and 100 on the static array, or will it use only 100 bytes total? And the pointer version, will it allocate the word size for the pointer besides the 100 bytes of the string, or will the pointer be optimized to the constant

C++ stateful allocator de-allocate issues

喜夏-厌秋 提交于 2019-12-24 06:42:12
问题 This issue is my misunderstanding of how the standard is using my custom allocator. I have a stateful allocator that keeps a vector of allocated blocks. This vector is pushed into when allocating and searched through during de-allocation. From my debugging it appears that different instances of my object (this*'s differ) are being called on de-allocation. An example may be that MyAllocator (this* = 1) is called to allocate 20 bytes, then some time later MyAllocator (this* = 2) is called to de

Why does the position of @autoreleasepool matter?

回眸只為那壹抹淺笑 提交于 2019-12-24 06:39:17
问题 I'm having trouble understanding how @autoreleasepool work. Consider the following example in which I am creating an AVAssetReader for an audiofile. To make the memory impact matter, I repeated this step 1000 times. #import <Foundation/Foundation.h> #import <AVFoundation/AVFoundation.h> void memoryTest() { NSURL *url = [[NSURL alloc] initWithString:@"path-to-mp3-file"]; AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil]; AVAssetReader *reader = [[AVAssetReader alloc]

EXC_BAD_ACCESS on NSSearchPathForDirectoriesInDomains

佐手、 提交于 2019-12-24 06:38:31
问题 I am working on a new release for an iOS application that was developed by another company but is now my responsibility. I have very little experience with objective C in general and iOS development in particular, but I'll try to convey my problem as best I can. I have the following method that I neither made nor changed over the course of my improvements: - (Boolean)ShouldWeDownloadImage:(NSString*)p_ImageName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,

Read/Write OpenCL memory buffers on multiple GPU in a single context

[亡魂溺海] 提交于 2019-12-24 06:35:16
问题 Assume a system with two distinct GPUs, but from the same vendor so they can be accessed from a single OpenCL Platform. Given the following simplified OpenCL code: float* someRawData; cl_device_id gpu1 = clGetDeviceIDs(0,...); cl_device_id gpu2 = clGetDeviceIDs(1,...); cl_context ctx = clCreateContext(gpu1,gpu2,...); cl_command_queue queue1 = clCreateCommandQueue(ctx,gpu1,...); cl_command_queue queue2 = clCreateCommandQueue(ctx,gpu2,...); cl_mem gpuMem = clCreateBuffer(ctx, CL_MEM_READ_WRITE,

Are arrays in structs freed on deletion?

六眼飞鱼酱① 提交于 2019-12-24 05:57:00
问题 If I were to use something like this in C++, struct socket_t { sockaddr_in address; char buffer[2048]; int FD; } socket_t *clients[256]; memset(clients, 0, 256); and then create objects in it, socket_t **free = (socket_t**) memchr(clients, 0, 256); *free = new socket_t; and then use delete on some of the elements, delete clients[index]; would all members be safely freed (especially the buffer)? I don't want to waste 2 KiB on each item I create. I'm asking this because I noticed sizeof returns

what kind of problems can lack of deallocation cause?

女生的网名这么多〃 提交于 2019-12-24 05:41:56
问题 i am currently experiencing a problem were i get *** glibc detected *** ./efit: free(): invalid next size (fast): 0x00000000006127f0 *** with the usual memory map and backtrace information that comes with a glibc error. i am, however, unable to find the cause of this problem. it seems like (basically) my entire program is finished by the time this happens. one thing i read online is that this could be due to lack of deallocation. now, i have been running the program without deallocating a few

what kind of problems can lack of deallocation cause?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 05:41:02
问题 i am currently experiencing a problem were i get *** glibc detected *** ./efit: free(): invalid next size (fast): 0x00000000006127f0 *** with the usual memory map and backtrace information that comes with a glibc error. i am, however, unable to find the cause of this problem. it seems like (basically) my entire program is finished by the time this happens. one thing i read online is that this could be due to lack of deallocation. now, i have been running the program without deallocating a few

Setting pointers to nil, objective-c

给你一囗甜甜゛ 提交于 2019-12-24 05:04:09
问题 I'm a bit confused about pointer memory being new to programming. So I add a UIBarButtonItem based on when a UITabBarController is selected like so: NSMutableArray *barItems = [[self.MainToolbar items] mutableCopy]; if (_sortButton == nil) { _sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStyleBordered target:self action:@selector(sortButtonPressed:)]; [barItems insertObject:_sortButton atIndex:0]; [self.MainToolbar setItems:barItems]; [_sortButton release];

Setting pointers to nil, objective-c

佐手、 提交于 2019-12-24 05:04:05
问题 I'm a bit confused about pointer memory being new to programming. So I add a UIBarButtonItem based on when a UITabBarController is selected like so: NSMutableArray *barItems = [[self.MainToolbar items] mutableCopy]; if (_sortButton == nil) { _sortButton = [[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStyleBordered target:self action:@selector(sortButtonPressed:)]; [barItems insertObject:_sortButton atIndex:0]; [self.MainToolbar setItems:barItems]; [_sortButton release];