memory-management

Destroy vs Deallocate

ぐ巨炮叔叔 提交于 2020-05-13 05:13:11
问题 In chapter 11 of Accelerated C++, the authors present a Vector class emulating the behaviour of std::vector using arrays. They use the allocator class to handle memory management. The role of the uncreate function is to destroy each element of the array and deallocate the space allocated for the array: template <class T> void Vec<T>::uncreate() { if (data) { // destroy (in reverse order) the elements that were constructed iterator it = avail; while (it != data) alloc.destroy(--it); // return

Destroy vs Deallocate

不羁的心 提交于 2020-05-13 05:13:07
问题 In chapter 11 of Accelerated C++, the authors present a Vector class emulating the behaviour of std::vector using arrays. They use the allocator class to handle memory management. The role of the uncreate function is to destroy each element of the array and deallocate the space allocated for the array: template <class T> void Vec<T>::uncreate() { if (data) { // destroy (in reverse order) the elements that were constructed iterator it = avail; while (it != data) alloc.destroy(--it); // return

Why did std::allocator lose member types/functions in C++17?

﹥>﹥吖頭↗ 提交于 2020-05-11 03:49:06
问题 While looking at std::allocator, I see that members: value_type , pointer , const_pointer , reference , const_reference , size_type , difference_type , and rebind have all been deprecated. Allocators will also no longer have the members: address , max_size , construct , or destroy . Why did this happen? Did it have something to do with polymophic allocators? 回答1: If you look at the relevant isocpp paper you can see that the first set you mention is now thought to be better placed in std:

Is there really no version of realloc() supporting alignment?

南笙酒味 提交于 2020-05-10 07:08:06
问题 There exist several aligned versions of the venerable malloc() , e.g.: #include <stdlib.h> int posix_memalign(void **memptr, size_t alignment, size_t size); void *aligned_alloc(size_t alignment, size_t size); #include <malloc.h> void *memalign(size_t alignment, size_t size); (originating in POSIX, glibc and Linux libc respectively). But - I can't seem to find any mention of a version of realloc() which supports alignment. Has it really never been implemented? It seems pretty trivial to

Is there really no version of realloc() supporting alignment?

*爱你&永不变心* 提交于 2020-05-10 07:07:26
问题 There exist several aligned versions of the venerable malloc() , e.g.: #include <stdlib.h> int posix_memalign(void **memptr, size_t alignment, size_t size); void *aligned_alloc(size_t alignment, size_t size); #include <malloc.h> void *memalign(size_t alignment, size_t size); (originating in POSIX, glibc and Linux libc respectively). But - I can't seem to find any mention of a version of realloc() which supports alignment. Has it really never been implemented? It seems pretty trivial to

Is there really no version of realloc() supporting alignment?

心不动则不痛 提交于 2020-05-10 07:06:26
问题 There exist several aligned versions of the venerable malloc() , e.g.: #include <stdlib.h> int posix_memalign(void **memptr, size_t alignment, size_t size); void *aligned_alloc(size_t alignment, size_t size); #include <malloc.h> void *memalign(size_t alignment, size_t size); (originating in POSIX, glibc and Linux libc respectively). But - I can't seem to find any mention of a version of realloc() which supports alignment. Has it really never been implemented? It seems pretty trivial to

PHP Fatal error allowed memory size exhausted

感情迁移 提交于 2020-05-09 04:55:53
问题 I'm writing a codeigniter application, upon doing a query i get hit with the following fatal error. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/cryd/_zcore/core/Loader.php on line 262 I could increase the allowed memory size, but it seems that the issue could be much more graver, that if it is a memory leak, i'd just be giving php more memory to play around with. The query is not even that intensive, it just returns one row

PHP Fatal error allowed memory size exhausted

南楼画角 提交于 2020-05-09 04:51:11
问题 I'm writing a codeigniter application, upon doing a query i get hit with the following fatal error. Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/cryd/_zcore/core/Loader.php on line 262 I could increase the allowed memory size, but it seems that the issue could be much more graver, that if it is a memory leak, i'd just be giving php more memory to play around with. The query is not even that intensive, it just returns one row

C++ Program Not Relying on Virtual Memory

孤街浪徒 提交于 2020-04-17 22:20:26
问题 A homework assignment I am working on requires that we exhaust our main memory so that the program uses virtual memory so that we can observe and measure the slowdown. However, when I get to sufficiently large memory values, I segfault or crash. I need to exhaust main memory and use virtual memory simultaneously and I was under the impression that windows (or other operating systems) would just take care of this, at least that is how it has been portrayed to me. The program I am using to

What is the difference between literals and non-literals, other than the fact that non-literals go into the heap?

梦想的初衷 提交于 2020-04-16 04:06:21
问题 I am confused by the difference between literals and non-literals (the ones that go on the heap, I do not know what they are called). For example, taking the String type as an example: We’ve already seen string literals, where a string value is hardcoded into our program. String literals are convenient, but they aren’t always suitable for every situation in which you want to use text. One reason is that they’re immutable. ... I do not understand the above, as we have already seen an example