memory-management

integer variable size in bss and data segment

隐身守侯 提交于 2020-01-31 05:43:45
问题 I am using a test program for understanding C memory model on linux 6.3 with kernal version 2.6.32-279.el6.x86_64 . First i have compile below code, #include <stdio.h> int main(void) { static int i = 100; /* Initialized static variable stored in DS*/ return 0; } on running size command , i got below , [root@rachitjain jan14]# size a.out text data bss dec hex filename 1040 488 16 1544 608 a.out then, after removing the intialization for static variable 'i' , my code becomes , include <stdio.h>

Difference between Uint8Array and Uint8ClampedArray

亡梦爱人 提交于 2020-01-30 13:56:09
问题 What is the difference between Uint8Array and Uint8ClampedArray in JavaScript? I understand that Uint8ClampedArray is used with canvas for pixel manipulations. Why is that and what is the benefit? 回答1: Looking at the examples for Uint8ClampedArray and Uint8Array, it looks like the difference is how values are treated when assigned. If you are trying to set one element to a clamped array to any value outside of the range 0-255 , it will simply default to 0 or 255 (depending on whether the

Reducing memory consumption of mysql on ubuntu@aws micro instance

跟風遠走 提交于 2020-01-30 13:51:07
问题 I have recently started on a PoC project wherein we are developing a small web app. The initial setup is done on a micro instance from AWS. We are on rails+mysql stack. After installing/running MySQL, I see that about 500+ MB RAM has been consumed already; leaving quite less for rest of the systems (micro instances have barely 620 MB RAM). Our app is fairly simple at this stage. Can I do something to reduce the memory consumed by MySQL server? Appreciate the help. 回答1: Change this setting in

Concatenating char buffer into a string

自作多情 提交于 2020-01-30 10:56:54
问题 In the following snippet, I receive the data until I have completely received all the data from the socket client. I keep on storing the data in a char buffer of size 300. ssize_t b; char buffer[300] while((b = recv(socket_fd,buffer,sizeof(buffer))) > 0) { // keep on receiving the data } But the problem is on each iteration, buffer gets refilled and old values are lost. How do I concatenate the buffer values into one, so that at the end of the loop I get the message as one complete string?

Why can't we delete an initialized pointer?

假如想象 提交于 2020-01-30 09:06:23
问题 I am initializing a char pointer with some random values, and when I am trying to delete it, I am unable to. Why is that? Here is what I am doing: int main() { char *s = new char[50]; /* * I know there is no reason for * using new if initializing, but * in order to use delete we need * to allocate using new. */ s = "Harry"; delete s; return 0; } 回答1: If you really want to practice with pointer, you need to fix your code. The main problem is you are trying to assign string literal( which is

Does Java Allow Direct Memory Access

拟墨画扇 提交于 2020-01-30 09:05:13
问题 I know C# allows you to use pointers in the unsafe context. But does Java have some similar memory access method? Java does not have pointers (for good reasons), so if there is a similar memory access method, what would it be exactly? 回答1: Well, there is a sun.misc.Unsafe class. It allows direct memory access, so you can implement some magic like reinterpret casts and so on. The thing is you need to use hacky reflection approach to get the instance and this class is not realy well documented.

Does Java Allow Direct Memory Access

南笙酒味 提交于 2020-01-30 09:05:09
问题 I know C# allows you to use pointers in the unsafe context. But does Java have some similar memory access method? Java does not have pointers (for good reasons), so if there is a similar memory access method, what would it be exactly? 回答1: Well, there is a sun.misc.Unsafe class. It allows direct memory access, so you can implement some magic like reinterpret casts and so on. The thing is you need to use hacky reflection approach to get the instance and this class is not realy well documented.

Why can't we delete an initialized pointer?

余生颓废 提交于 2020-01-30 09:04:06
问题 I am initializing a char pointer with some random values, and when I am trying to delete it, I am unable to. Why is that? Here is what I am doing: int main() { char *s = new char[50]; /* * I know there is no reason for * using new if initializing, but * in order to use delete we need * to allocate using new. */ s = "Harry"; delete s; return 0; } 回答1: If you really want to practice with pointer, you need to fix your code. The main problem is you are trying to assign string literal( which is

ActionScript - Difference Between Primitive / Non-Primitive Objects for Memory Management?

寵の児 提交于 2020-01-27 20:59:48
问题 my understanding is that primitive types ( uint, string, Number, etc. ) of a class do not need to be set to null for garbage collection. for example, i am not required to write this dispose() method in the following class: package { //Imports import flash.display.Shape; //Class public class DrawSquare extends Shape { //Properties private var squareColorProperty:uint; //Constructor public function DrawSquare(squareColor:uint) { squareColorProperty = squareColor; init(); } //Initialize private

ActionScript - Difference Between Primitive / Non-Primitive Objects for Memory Management?

夙愿已清 提交于 2020-01-27 20:59:27
问题 my understanding is that primitive types ( uint, string, Number, etc. ) of a class do not need to be set to null for garbage collection. for example, i am not required to write this dispose() method in the following class: package { //Imports import flash.display.Shape; //Class public class DrawSquare extends Shape { //Properties private var squareColorProperty:uint; //Constructor public function DrawSquare(squareColor:uint) { squareColorProperty = squareColor; init(); } //Initialize private