memory-management

total memory of a C++ class object

可紊 提交于 2019-12-24 11:53:46
问题 Why does the following piece of code gives 24 as an answer? That is, how is the total size of the object of following class X, 24 bytes? I'm using 64-bit machine. #include <bits/stdc++.h> using namespace std; class X { vector <bool> f; int b; public: X(){ f.push_back(true); } }; int main(){ X ob; cout<<sizeof(ob); return 0; } 回答1: That is, how is the total size of the object of following class X, 24 bytes? I'm using 64-bit machine. C++ makes few guarantees about type sizes and none about the

What is faster and more convenient: Hashtable or Dictionary<int, double>()?

╄→гoц情女王★ 提交于 2019-12-24 11:47:48
问题 Preamble: I'm working at heavy-loaded applicaion that produces large data arrays. I wrote the following class using System; using System.Collections; using System.Collections.Generic; namespace CSharpSampleApplication.Data.CoreObjects { [Serializable] public class CalcItem { public CalcItem() { _additional = new Hashtable(); } private readonly Hashtable _additional; public bool ContainsKey(int id) { return _additional.ContainsKey(id); } public void Add(int id, double value) { _additional.Add

How to “free” an Microsoft.Office.Interop.Word.Application wordApp instance?

二次信任 提交于 2019-12-24 11:29:43
问题 What are alternatives to "free" this object? it normally happens when call the .Exit() method is called, but in this case, I can't do this because the user that should close the word application instance. I thought to do wordApp = null or call GC.Collect(); what's the best solution and why? thanks in advance. I'm using this currently: public static void Free() { if (wordApp != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp); GC.Collect(); } } 回答1: The most aggressive

Spark Encoders: when to use beans()

巧了我就是萌 提交于 2019-12-24 11:16:13
问题 I came across a memory management problem while using Spark's caching mechanism. I am currently utilizing Encoder s with Kryo and was wondering if switching to beans would help me reduce the size of my cached dataset. Basically, what are the pros and cons of using beans over Kryo serialization when working with Encoder s? Are there any performance improvements? Is there a way to compress a cached Dataset apart from caching with SER option? For the record, I have found a similar topic that

Error message “MemoryError” in Python

隐身守侯 提交于 2019-12-24 11:04:03
问题 Here's my problem: I'm trying to parse a big text file (about 15,000 KB) and write it to a MySQL database. I'm using Python 2.6, and the script parses about half the file and adds it to the database before freezing up. Sometimes it displays the text: MemoryError. Other times it simply freezes. I figured I could avoid this problem by using generator's wherever possible, but I was apparently wrong. What am I doing wrong? When I press Ctrl + C to keyboard interrupt, it shows this error message:

Confusing double free error message/memory leak in iPhone app

只愿长相守 提交于 2019-12-24 11:02:00
问题 EDIT - added .h file I'm having difficulty trying to find the cause of a double free error. Steps taken to solve 1) Used the Zombies tool. Zombies reports that tid is being double freed 2) Set a breakpoint on malloc_error_break. This identifitied the following code segment as faulty: - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [connection release]; [ldestination release]; [ldeparts_from release]; [ltime release]; [lcs_id release]; /// It breaks here

How should I return the result of a binary-operation function in a C library?

别来无恙 提交于 2019-12-24 10:38:17
问题 I'm working on a C library, and part of it deals with some mathematical types and manipulating them. Each type has a factory constructor/destructor function that allocates and frees them dynamically. For example: /* Example type, but illustrates situation very well. */ typdef struct { float x; float y; float z; } Vector3D; /* Constructor */ Vector* Vector3D_new(float x, float y, float z) { Vector3D* vector = (Vector3D*) malloc(sizeof(Vector3D)); /* Initialization code here...*/ return vector;

How do I check if ConcurrentLinkedQueue leaves garbage (dereferenced instances) for the GC?

久未见 提交于 2019-12-24 10:35:56
问题 I am using a bunch of ConcurrentLinkedQueue s in my application and the GC overhead is huge. How do I check if the ConcurrentLinkedQueue is the culprit? Is there a standard way in Java to profile these data structures for memory allocation/deallocation? 回答1: One way to do it is to write a simple test program and run it with the -verbose:gc JVM option. For example, the code: import java.util.concurrent.ConcurrentLinkedQueue; public class TestGC { public static void main(String[] args) throws

Does system release my objects when the application is terminated?

我的梦境 提交于 2019-12-24 10:15:01
问题 i always wonder sometimes that when i run my app an app pool is created and my app gets loaded inside the app pool and when i hit the home button my app is terminated i.e. the pool in which my app was residing will be terminated so in this case what will happen to those objects if i do not release such objects i think they will be terminated too but this methodology is not recommended by apple god knows for what reason. Can any gentleman provide me a solid answer for this question because it

Memory being allocated

梦想的初衷 提交于 2019-12-24 10:12:13
问题 By using the Chrome Development Tools, I found out arrays and objects were being allocated. I gone through my code looking for the obvious [] , {} and new . But there isn't any. I have checked functions that create a new [] , {} , new and looked to see where those functions are used, and I've learnt not to use them. So, how else can memory be allocated? This is a problem for me, because every time GC kicks in, it blocks the main loop and the animation becomes inconsistent. 回答1: It is