memory

Why deallocating heap memory is much slower than allocating it?

两盒软妹~` 提交于 2021-02-05 04:55:46
问题 This is an empirical assumption (that allocating is faster then de-allocating). This is also one of the reason, i guess, why heap based storages (like STL containers or else) choose to not return currently unused memory to the system (that is why shrink-to-fit idiom was born). And we shouldn't confuse, of course, ' heap ' memory with the ' heap '-like data structures. So why de-allocation is slower ? Is it Windows -specific (i see it on Win 8.1 ) or OS independent? Is there some C++ specific

Why deallocating heap memory is much slower than allocating it?

倖福魔咒の 提交于 2021-02-05 04:53:05
问题 This is an empirical assumption (that allocating is faster then de-allocating). This is also one of the reason, i guess, why heap based storages (like STL containers or else) choose to not return currently unused memory to the system (that is why shrink-to-fit idiom was born). And we shouldn't confuse, of course, ' heap ' memory with the ' heap '-like data structures. So why de-allocation is slower ? Is it Windows -specific (i see it on Win 8.1 ) or OS independent? Is there some C++ specific

Passing arrays in C: square brackets vs. pointer

独自空忆成欢 提交于 2021-02-04 17:14:26
问题 I'm wanting to pass an array into a function. From what I can see, there are 2 ways of doing this: 1. void f (int array[]) { // Taking an array with square brackets } 2. void f (int *array) { // Taking a pointer } Each one is called by: int array[] = {0, 1, 2, 3, 4, 5}; f (array); Is there any actual difference between these 2 approaches? 回答1: In your specific example there is no difference. In more general case one difference between these two approaches stems from the fact that in case of [

PHP Memory Allocation and Deallocation

久未见 提交于 2021-02-04 08:17:25
问题 So, I am running a long-running script that is dealing with memory sensitive data (large amounts of it). I (think) I am doing a good job of properly destroying large objects throughout the long running process, to save memory. I have a log that continuously outputs current memory usage (using memory_get_usage()), and I do not notice rises and drops (significant ones) in memory usage. Which tells me I am probably doing the right thing with memory management. However, if I log on to the server

How would the memory look like for this object?

青春壹個敷衍的年華 提交于 2021-01-31 06:45:11
问题 I am wondering how the memory layout for this class (its object) would look like: class MyClass { string myString; int myInt; public MyClass(string str, int i) { myString = str; myInt = i; } } MyClass obj = new MyClass("hello", 42); Could anyone visualize that? Update: Based on the answer from Olivier Rogier and the comments from ckuri and Jon Skeet I tried to come up with a high level chart, heavily influenced by the devblog article mentioned by ckuri. So to my understanding: obj (8 bytes

How would the memory look like for this object?

我只是一个虾纸丫 提交于 2021-01-31 06:40:31
问题 I am wondering how the memory layout for this class (its object) would look like: class MyClass { string myString; int myInt; public MyClass(string str, int i) { myString = str; myInt = i; } } MyClass obj = new MyClass("hello", 42); Could anyone visualize that? Update: Based on the answer from Olivier Rogier and the comments from ckuri and Jon Skeet I tried to come up with a high level chart, heavily influenced by the devblog article mentioned by ckuri. So to my understanding: obj (8 bytes

Efficient algorithm for removing items from an array in place

我只是一个虾纸丫 提交于 2021-01-29 22:10:55
问题 I'm looking for an efficient JavaScript utility method that in O(n) will remove a set of items from an array in place . You can assume equality with the === operator will work correctly. Here is an example signature (written in TypeScript for type clarity) function deleteItemsFromArray<T>(array: T[], itemsToDelete: T[]) { ... } My thought is to do this in two passes. The first pass gets the indexes that need to be removed. The second pass then compacts the array by copying backwards from the

Struct alignment suggestions?

喜欢而已 提交于 2021-01-29 17:06:40
问题 I am sending data over a network. To send that data over a network I am packing it into a byte array. Right now the data type consist of a byte and 3 floats making it 13 bytes total. To read this I need to know the size of the structure. Using Marshal's sizeOf does not return the "correct" size of my serialized byte array. Now I know what is happening. Marshal is returning me the managed aligned size of my struct. I also know if I flag it [StructLayout(LayoutKind.Sequential, Pack = 1)] then

Functions and variable space with threading using clone

跟風遠走 提交于 2021-01-29 08:14:40
问题 I currently intend to implement threading using clone() and a question is, if I have all threads using the same memory space, with each function I call in a given thread, will each thread using a different part of memory when the same function is called, or do I do have todo something to ensure this happens? 回答1: Each thread will be using the same memory map overall but a different, separate thread-local stack for function calls. When different threads have called the same function (which

How does IOS manage memory of backgrounded apps?

a 夏天 提交于 2021-01-29 07:02:38
问题 I have an IOS app that during testing seems to work fine until... The app has been in the background for quite some time, say 24 hours... and meanwhile lots of activity has taken place in other apps (videos, audio, location... battery going low... lots of memory being used). Then when I bring my app back into the foreground, it acts glitchy such as having no audio... and then crashes after a short while. I KNOW this is not the best description, but it has only happened once and I'm not asking