memory-management

Are members in a c++ class guaranteed be contiguous?

我怕爱的太早我们不能终老 提交于 2021-02-08 06:32:21
问题 Are class members in c++ guaranteed to be contiguous? I've tried running the following code with almost all popular c++ compilers, and all of them yield the result 4, which is the relative address of the variable y. Is that a coincidence, or is it guaranteed by the language specifications to be this way? Isn't it possible that the compiler will not make the members x and y contiguous with the class basic address/ contiguous with each other? Please note that this thread does not answer this

How to determine memory usage in my .NET application

早过忘川 提交于 2021-02-07 12:23:32
问题 I have a website where some user can upload his dll. I need to create an instance from this dll and call a specific method. Moreover, I need to do it with several dll's in 1 process, so it is not an option for me to use System.Diagnostics.Process. Is there a way to determine how much memory does this method call use or limit it in my application runtime? Thanks in advance for any help 回答1: Memory usage in .Net is very difficult to gauge - It will depend on a lot of factors like whether

How to correctly dereference then delete a JavaScript Object?

人走茶凉 提交于 2021-02-07 12:01:46
问题 I would like to know the correct way to completely dereference a JavaScript Object from memory. To ensure it's deletion without it dangling in memory, and that the garbage collector removes the object. When I looked and this question Deleting Objects in JavaScript. It was explained that if you delete all the references of object, the GC will remove it from memory. I want to know how do I go about removing references from an object that has both methods and properties. Suppose you have and

Incorrect memory access: why is my kernel *not* crashing

喜欢而已 提交于 2021-02-07 10:24:40
问题 I wanted to show to somebody an exemple of incorrect memory access (kernelspace trying to access userspace memory leading to a bug). Thus, I took an old tutorial as a POC, the important part is : static ssize_t dev_write(struct file *filep, const char *buffer, size_t len, loff_t *offset){ sprintf(message, "%s(%zu letters)", buffer, len); // appending received string with its length // [...] } This causes a crash in one of my environment tests, which is the expected behavior (I access the

javascript new keyword and memory leaks?

依然范特西╮ 提交于 2021-02-07 10:24:22
问题 let x = new MyClass(); ...[more code] let x = new MyClass(); Will the first instance of MyClass get garbaged collected automatically? Or do I need to explicitly x = null or something like that before the second assignment, in order to avoid a memory leak? 回答1: JavScript's memory is managed automatically, so objects that are deemed "unreachable" are collected by the garbage collector. In the example you provided, the object stored in x will be garbage-collected so long as it isn't reachable

Incorrect memory access: why is my kernel *not* crashing

孤街浪徒 提交于 2021-02-07 10:22:27
问题 I wanted to show to somebody an exemple of incorrect memory access (kernelspace trying to access userspace memory leading to a bug). Thus, I took an old tutorial as a POC, the important part is : static ssize_t dev_write(struct file *filep, const char *buffer, size_t len, loff_t *offset){ sprintf(message, "%s(%zu letters)", buffer, len); // appending received string with its length // [...] } This causes a crash in one of my environment tests, which is the expected behavior (I access the

Where does local variables actually allocated within CLR?

别来无恙 提交于 2021-02-07 08:28:40
问题 I'm just going inside the CLR and IL and I'm confused by this thing. I have the following C# code: int x = 1; object obj = x; int y = (int)obj; And IL disassemble for this // Code size 18 (0x12) .maxstack 1 .locals init ([0] int32 x, [1] object obj, [2] int32 y) IL_0000: nop IL_0001: ldc.i4.1 IL_0002: stloc.0 IL_0003: ldloc.0 IL_0004: box [mscorlib]System.Int32 IL_0009: stloc.1 IL_000a: ldloc.1 IL_000b: unbox.any [mscorlib]System.Int32 IL_0010: stloc.2 IL_0011: ret So, the ldloc.0 instruction

Where does local variables actually allocated within CLR?

你。 提交于 2021-02-07 08:22:34
问题 I'm just going inside the CLR and IL and I'm confused by this thing. I have the following C# code: int x = 1; object obj = x; int y = (int)obj; And IL disassemble for this // Code size 18 (0x12) .maxstack 1 .locals init ([0] int32 x, [1] object obj, [2] int32 y) IL_0000: nop IL_0001: ldc.i4.1 IL_0002: stloc.0 IL_0003: ldloc.0 IL_0004: box [mscorlib]System.Int32 IL_0009: stloc.1 IL_000a: ldloc.1 IL_000b: unbox.any [mscorlib]System.Int32 IL_0010: stloc.2 IL_0011: ret So, the ldloc.0 instruction

Where does local variables actually allocated within CLR?

妖精的绣舞 提交于 2021-02-07 08:21:47
问题 I'm just going inside the CLR and IL and I'm confused by this thing. I have the following C# code: int x = 1; object obj = x; int y = (int)obj; And IL disassemble for this // Code size 18 (0x12) .maxstack 1 .locals init ([0] int32 x, [1] object obj, [2] int32 y) IL_0000: nop IL_0001: ldc.i4.1 IL_0002: stloc.0 IL_0003: ldloc.0 IL_0004: box [mscorlib]System.Int32 IL_0009: stloc.1 IL_000a: ldloc.1 IL_000b: unbox.any [mscorlib]System.Int32 IL_0010: stloc.2 IL_0011: ret So, the ldloc.0 instruction

Increasing C++ Program CPU Use

旧巷老猫 提交于 2021-02-07 08:00:43
问题 I have a program written in C++ that runs a number of for loops per second without using anything that would make it wait for any reason. It consistently uses 2-10% of the CPU. Is there any way to force it to use more of the CPU and do a greater number of calculations without making the program more complex? Additionally, I compile with C::B on a Windows computer. Essentially, I'm asking whether there is a way to make my program faster by increasing usage of CPU, and if so, how. 回答1: Assuming