heap

Casting a pointer to an int

巧了我就是萌 提交于 2019-12-19 04:14:36
问题 I am writing my own functions for malloc and free in C for an assignment. I need to take advantage of the C sbrk() wrapper function. From what I understand sbrk() increments the program's data space by the number of bytes passed as an argument and points to the location of the program break. If I have the following code snippet: #define BLOCK_SIZE 20 int x; x = (int)sbrk(BLOCK_SIZE + 4); I get the compiler error warning: cast from pointer to integer of different size . Why is this and is

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

丶灬走出姿态 提交于 2019-12-19 04:06:00
问题 I can't make any search with npm: npm search material ..results with the following error: npm WARN Building the local index for the first time, please be patient FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory I tried with the following command npm --max_old_space_size=16384 search material but I had the same result. npm version is 3.10.3 回答1: According to npm's bug tracker, this has been fixed in npm@4.0.0. (see thread). Searching works fine for me after

Is there a fundamental difference between malloc and HeapAlloc (aside from the portability)?

十年热恋 提交于 2019-12-19 02:27:13
问题 I'm having code that, for various reasons, I'm trying to port from the C runtime to one that uses the Windows Heap API. I've encountered a problem: If I redirect the malloc / calloc / realloc / free calls to HeapAlloc / HeapReAlloc / HeapFree (with GetProcessHeap for the handle), the memory seems to be allocated correctly (no bad pointer returned, and no exceptions thrown), but the library I'm porting says "failed to allocate memory" for some reason. I've tried this both with the Microsoft

Can we use binary search tree to simulate heap operation?

二次信任 提交于 2019-12-18 21:54:43
问题 I was wondering if we can use a binary search tree to simulate heap operations (insert, find minimum, delete minimum), i.e., use a BST for doing the same job? Are there any kind of benefits for doing so? 回答1: Sure we can. but with a balanced BST. The minimum is the leftest element. The maximum is the rightest element. finding those elements is O(logn) each, and can be cached on each insert/delete, after the data structure was modified [note there is room for optimizations here, but this naive

Can we use binary search tree to simulate heap operation?

痴心易碎 提交于 2019-12-18 21:54:42
问题 I was wondering if we can use a binary search tree to simulate heap operations (insert, find minimum, delete minimum), i.e., use a BST for doing the same job? Are there any kind of benefits for doing so? 回答1: Sure we can. but with a balanced BST. The minimum is the leftest element. The maximum is the rightest element. finding those elements is O(logn) each, and can be cached on each insert/delete, after the data structure was modified [note there is room for optimizations here, but this naive

Android: Out of memory error

蓝咒 提交于 2019-12-18 17:11:41
问题 When I minimize my Android App for about 4 or 5 times, I always get the following error: 02-01 19:24:11.980: E/dalvikvm-heap(22362): Out of memory on a 3686416-byte allocation. 02-01 19:24:12.000: E/dalvikvm(22362): Out of memory: Heap Size=62755KB, Allocated=55237KB, Limit=65536KB 02-01 19:24:12.000: E/dalvikvm(22362): Extra info: Footprint=62435KB, Allowed Footprint=62755KB, Trimmed=2144KB 02-01 19:24:12.000: E/Bitmap_JNI(22362): Create Bitmap Failed. 02-01 19:24:12.000: E/Bitmap_JNI(22362)

Memory leak checking on Windows with QT and MinGW32

眉间皱痕 提交于 2019-12-18 13:17:01
问题 Lately I have been developing in C++ with QT Creator. All is well and I'm nearly at the point of packaging and distributing my application. But obviously before any release you better make sure you have everything right. So I'm at the testing stage, and something tells me that I have some slight memory issues. Nothing serious, but I like to obsess over these ;-). So I decided to try some memory leak detection libraries. For starters I looked at this question. I disregarded Purify and Insure++

Max-Heapify A Binary Tree

瘦欲@ 提交于 2019-12-18 13:06:30
问题 This is one of the interview questions I recently came across. Given the root address of a complete or almost complete binary tree, we have to write a function to convert the tree to a max-heap. There are no arrays involved here. The tree is already constructed. For e.g., 1 / \ 2 5 / \ / \ 3 4 6 7 can have any of the possible max heaps as the output-- 7 / \ 3 6 / \ / \ 2 1 4 5 or 7 / \ 4 6 / \ / \ 2 3 1 5 etc... I wrote a solution but using a combination of pre and post order traversals but

How to programmatically get the address of the heap on Linux

亡梦爱人 提交于 2019-12-18 12:34:37
问题 I can get the address of the end of the heap with sbrk(0) , but is there any way to programmatically get the address of the start of the heap, other than by parsing the contents of /proc/self/maps ? 回答1: I think parsing /proc/self/maps is the only reliable way on the Linux to find the heap segment. And do not forget that some allocators (including one in my SLES) do use for large blocks mmap() thus the memory isn't part of the heap anymore and can be at any random location. Otherwise,

What is the difference between using the box keyword and Box::new?

£可爱£侵袭症+ 提交于 2019-12-18 12:24:59
问题 Is box just syntactic sugar or can it be applied to use cases where Box::new is not sufficient? I read somewhere that box is unstable, does that mean I can only use it with the nightly Rust versions? 回答1: Box::new is just a function, like any other function. It is not special in any way whatsoever. It is grubby and smells faintly of very-close-to-the-expiration date cheese. box is magic and made up ground-up pixies and the dreams of little children. It is dressed in the finest, swankiest