memory-management,vala , How can I add a reference to a value-type in vala

How can I add a reference to a value-type in vala


Tag: memory-management,vala

In c++ I can add a reference to a value type, for example :

int a = 12;
int &b = a;

cout << "a = " << a << ", b = " << b << endl;

Will give : a = 11, b = 11

Is there a way to do the same in vala without using pointers ?


Is there a way to do the same in vala


without using pointers ?


If, however, you are passing them to a function, you can use a ref parameter:

void decrement (ref value) {

void do_stuff () {
  int a = 12;
  decrement (ref a);
  assert (a == 11);


Is free() zeroing out memory?

Until today I lived in belief that calling free() on memory space releases it for further allocation without any other modifications. Especially, considering this SO question that clearly states that free() DOESN'T zero out memory. Yet, let's consider this piece of code (test.c): #include<stdlib.h> #include<stdio.h> int main() { int* pointer;...

Operator Overloading without memory copies

Imagine we have the type A and we want to do the following operation: A operator -(const A& a, const A& b) { A c; //... return c; } When we call this operator, we do something like this: A c; c = a - b; Basically we are allocating...

Weak and strong property implementation

I want to better understand strong and weak pointers implementation, and i figure out assumptions, about how their setter methods would look like (correct me if i wrong please). First, strong pointer, look like: - (void)setObj:(NSObject*)Obj // Setting Strong Obj { //First, check either we trying to set old value...

Async Function in Vala - Yield & Callback

I'm developing a project written in Vala and GTK +, I need to implement an asynchronous function, therefore I set out to make an example of test ... and for some reason I get the following error: async.vala:31.3-31.20: error: Access to async callback `asyncProc.callback' not allowed in this context asyncProc.callback...

uninitialized data segment of program memory

In Uninitialized Data Segment, the kernel initialize the uninitialized variable to 0. But if we directly use an uninitialized variable (for eg. int sum; and not int sum=0; ) and use it in program like sum=sum+n(n be any number), sum will take any garbage value. So why the sum will...

Java how to limit number of threads acting on method

I have java method in my web application doing heavy file operation. The thing is, if more than 5 threads come simultaneously (which will come in testing phase) it breaks down. I mean it cannot handle heavy traffic. That's why I want to handle maximum 5 requests at a time...

Modern C++ idiom for allocating / deallocating an I/O buffer

For I/O work, I need to read N bytes into a buffer. N is known at run time (not compile time). The buffer size will never change. The buffer is passed to other routines to compress, encrypt, etc: it's just a sequence of bytes, nothing higher than that. In C,...

Memory analysis in Android: dominator_tree does not show all the instances of some objects

I'm using Eclipse Memory Analyzer, for testing the behavior of MainActivity in my Android app. I've rotated my device exactly 10 times, so I have created 11 instances of MainActivity class. Looking at the Histogram tab in Eclipse Memory Analyzer, I obtain this The entire list objects (right click ->...

What is a “non-weak zeroing reference”

In the OS X v10.11 beta release notes, I find the following: NSNotificationCenter and NSDistributedNotificationCenter no longer send notifications to registered observers that may be deallocated. If the observer is able to be stored as a zeroing-weak reference the underlying storage stores the observer as a zeroing weak reference. Alternatively,...

Proper memory cleanup with c_str() and const char *

I have a function that takes a (char* const*). The data I am provided is in a std::string. So I'm doing this: void blahblah(std::string str) { const char * cc = str.c_str(); ConstCharFunction(&cc); } This works well. My question is do I need to clean-up the memory used by the...

Getting many memory errors when try to run it for few days in my web crawler [on hold]

I am developing a web crawler application. When i run the program i am getting these error messages below: i've got these errors after running the program for more that 3 hours. I tried to allocate memory by changing eclipse.ini setting to 2048 MB of ram as it was answered...

function to get 2d-arrays from stack and heap

Consider a simple struct, Foo, which contains a pointer to some other strucrt, Baz. and a two-dimensional array, (stack-allocated): Foo arr[ARR_SIZE][ARR_SIZE]; Next, consider a function which mallocs (in the heap, obviously) a memory for a new 2d-array of Foos. A code snippet: Foo** arr_copy = malloc(sizeof(Foo*) * ARR_SIZE); for (int...

Multipart form uploads + memory leaks in golang?

The following server code: package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter, r *http.Request) { file, _, err := r.FormFile("file") if err != nil { fmt.Fprintln(w, err) return } defer file.Close() return } func main() { http.ListenAndServe(":8081", http.HandlerFunc(handler)) } being run and then calling it with: curl -i...

Memory management in Contiki-OS

I am trying to create a port for Contiki-os to LPC1347, and i have a question as to how exactly is memory handled in Contiki. Protothreads are stack-less and no "real threads" are used so everything is basically on the same stack, so it is basically static memory allocation. I...

Is there a better way to do this than writing a wrapper allocator that stores a reference to a stateful allocator object?

For example: struct Foo { MyPoolAlloc<char> pool; std::vector<int , MyPoolAlloc<char>> vec_int; // The wrapper allocator would replace MyPoolAlloc<> here. std::vector<std::function<void()> , MyPoolAlloc<char>> vec_funcs; // The wrapper allocator would replace MyPoolAlloc<> here. Foo() : vec_int(pool) , vec_funcs(pool) {} // I want to store lambdas with captured variables using the custom allocator...

How to get current memory page size in C#

I need to determine the memory page size in C# without using "Kernel32.dll" SYSTEM_INFO si; GetSystemInfo(&si); This is very important because the code should be cross platform and we should not have platform specific code. Is there any .NET class who provides that data? Thanks, Valentin...

When calling append on stringbuilder, are we adding strings to the heap?

I am wondering about the benefits of using stringbuilder when it comes to memory usage in C#. If you have the following scenario: var strBuilder = new StringBuilder(); for(int i=0;i<1000;i++) { strBuilder.Append(i); /// is this not calling i.ToString(); ??? strBuilder.Append(','); /// this i character comma strBuilder.Append(" and "); /// this...

Valgrind says about “Invalid write” in fclose()

I created a stream using fmemopen(). I am closing it with fclose() and freeing the buffer after reading. Valgrind reports about problem at fclose() line: ==9323== Invalid write of size 8 ==9323== at 0x52CAE52: _IO_mem_finish (memstream.c:139) ==9323== by 0x52C6A3E: [email protected]@GLIBC_2.2.5 (iofclose.c:63) ==9323== by 0x400CB6: main (main.cpp:80) ==9323== Address 0xffefffa80 is...

Why I cannot use “fgets” to read a string to an element of my Struct?

I'm trying to create a program almost like "bank" using struct, but when the program should have read the string (variable "nome" that is name in portuguese) it totally ignore the "fgets" that I used. This is the part that I was talking about : printf("\nNome: \n"); fgets(vet[cont+1].nome, sizeof(vet[cont+1].nome), stdin);...

munmap_chunck(): invalid pointer in c

I have a program that I've written to do some data analysis, and this data is stored in a global structure called P. I allocate the memory for this structure in one function and then, since I need it for the entire program, don't call free until the very end...

c++ dynamically declared array fails to work

I am trying to read the file's data into a dynamically declared array, using double *data = new double[14141414]() declaration. Note, it is rather a large file; hence large size of an array. The problem is I can not put all the data into an array as somewhere around index=14000000...

Sharing std::string across shared memory

I wish to share a std::string across processes using shared memory. However, I'm concerned about where the string object is allocated, on the stack, or heap, as this will affect the share. Referring to this, MSDN Forum says : please note that in new STL (Visual Studio 2003 and...

QEvent ownership

I want to send both predefined and custom QEvent to a Qt application. Is the event required be allocated on the heap or can I just pass the pointer to a object on the stack? QKeyEvent stackevent(QEvent::KeyPress); QKeyEvent* heapevent = new QKeyEvent(QEvent::KeyPress); QEvent * event; event = &stackevent; //valid ??...

Simple explanation about loading files into memory,visual-studio-2010,memory-management
What does it mean to "load into memory"? I watched some videos online where they were talking about reducing processing reports times, and they constantly say "you don't want to load a huge file into memory, instead read line by line." Can I have an example of what loading a...

Retain cycle in Swift when Object A has Object B as a property and Object B has an array property that contains Object A?

Confused about a situation that might be a retain cycle? I understand that if class Object-A { var b: Object-B } and class Object-B { var a: Object-A ] then above is horrible design because if you do var a = Object-A() var b = Object-B() a.b = b b.a...

Explanation of why allocating a large array results in segmentation fault in C [duplicate]

This question already has an answer here: Segmentation fault on large array sizes 5 answers Memory allocation for global and local variables 3 answers I'm not too experienced in C, but I've been recently writing some program in the language to speed it up a little bit (it was...

Temporary variable destroyed with overloaded + and += operator

I am getting a segfault because I believe my temporary variable is being destroyed (freeing allocated memory) before the operators are done using it. This is the code in my main: int main(int argc, char *argv[]) { Bcd b1 = Bcd(100), b2 = Bcd(20), b3 = Bcd(50); b3 += b1...

Why should I dimension my variables in VBA really?

They used to say it was about memory management. However, having a look at things I find that failure to dimension a variable will default it to a variant data type which allocates 22 bytes of memory. Let's consider just a single megabyte of memory. 1,000,000 bytes. This means I...

Using and having allocation memory issue

I'm new to programming, I've been making an app for the last 3 months and learned a few things. But I haven't come across to how to solve this issue. I've been using as my server, sending pictures, saving user data etc. With all of this data the app...

Most efficient way to clone a list into an existing list, minimizing memory reallocation?

I have a need to clone an existing list into another, existing list. As the environment demands very high performance, I need to eliminate unnecessary memory reallocation. The most efficient algorithm I can think of is the following, which will increase the capacity of the destination list to match the...

Unable to increase PHP Memory Limit

I am running into an issue with a project I am working with on my localhost, where I am unable to increase the PHP memory_limit setting. I've tried increasing it directly in the php.ini config: memory_limit = 1024M I've tried increasing it in the projects .htaccess file: php_value memory_limit 1024M...

Memory error in set resize

Here's a structure of set that I've written: struct state_set { struct state ***state_array; size_t *slot_sizes; size_t *slot_memory; }; Here's an initializer: struct state_set *state_set_init() { struct state_set *new_set = malloc(sizeof(struct state_set)); new_set->state_array = malloc(ARRAY_SIZE * sizeof(struct state**)); new_set->slot_sizes = malloc(ARRAY_SIZE * sizeof(size_t)); new_set->slot_memory = malloc(ARRAY_SIZE * sizeof(size_t)); for (int...

Fortran memory allocation does not give an error, but the program is killed by OS at initialization

Given the minimal working example provided below, do you know why the memory allocation error does not occur at memory allocation step? As I checked, when I use valgrind to run the code, or add parameter source=0.0 to memory allocation statement, then I have, as expected, the memory allocation error....

DataTable does not release memory

I have a data loading process that load a big amount of data into DataTable then do some data process, but every time when the job finished the DataLoader.exe(32bit, has a 1.5G memory limit) does not release all the memory being used. I tried 3 ways to release memory: DataTable.Clear()...

memory content not erased after deleting my pointer (on a simple example) [duplicate]

This question already has an answer here: Can a local variable's memory be accessed outside its scope? 16 answers Here is a simple of example of a question I have: I create a pointer of integer (value 5), I print the pointer (hence the address) of the memory case...

Allocating memory for pointers inside structures in functions

Let's say I declare a structure as it follows: typedef struct { int *numbers; int size; // Size of numbers once treated as array } sstruct; And I create in main() a pointer to structure (in order to later pass it by reference) using sstruct *example;. Then I have a...

Free memory of byte[]

I'm currently struggling with memory usage in c#. The tool I'm currently working on is able to up- and download files. For that it is using byte arrays as buffers for the file contents. After an up- or download operation I can dispose the WebResponse and the Stream(+Reader/Writer) objects, however...

Memory Management (Allocating Pages/Frames to Logical Addresses)

I am new to Operating Systems and I was following this handbook which I am reading to get a better grasp on how computers really work. However having stumbled upon Memory Management I found it somewhat confusing when allocating Frames to Pages using Page tables. Say Page/Frame size is 4K...

How to cast a compact type in Vala?

I am using the gobject-introspection-1.0 library from Vala to dynamically load gir modules. As I need to call an initialization function having a fixed name, I retrieve a BaseInfo object from Repository.find_by_name. Now, I want to invoke this function with GI.CallableInfo.invoke, which needs a GI.CallableInfo object. Luckily, GI.CallableInfo inherits from...

How can I ensure an emxArray is correctly allocated in generated C code?

I have the following .m file (named testmemoryallocation.m), targeted for code generation in Matlab Coder. This is just a test file demonstrating the concept, of course. function output = testmemoryallocation(dim) %#codegen %TESTMEMORYALLOCATION Tests allocation of large 3D arrays output = coder.nullcopy(zeros([dim, dim, dim])); output(:) = 5; end I build this...

Disadvantages of calling realloc in a loop

I'm trying to implement some math algorithms in C on Windows 7, and I need to repeatedly increase size of my array. Sometimes it fails because realloc can't allocate memory. But if I allocate a lot of memory at once in the beginning it works fine. Is it a problem...

How are Strings created and stored in Java?

To understand how String objects are created and stored, I tried the following program and I see output against which I have query. Can somebody please help? package corejava.immutable; public class StringTester { public static void main(String[] args) { // TODO Auto-generated method stub String s1 = "Omkar Patkar"; String...

Deleting a dynamically allocated 2D array [duplicate]

This question already has an answer here: delete vs delete[] [duplicate] 4 answers So I'm used to memory management in C where free(pointer) will free up all space pointed to by pointer. Now I'm confusing myself when attempting to do something simple in C++. If I have a 2D...

Cannot free fileName char * after fclose

I am trying to free my file name (char * pointer) but got an error : Heap corruption detected: after normal block (#65) at 0x.... The code: static FILE *initializeIndexFile(char *database, char **indexFileName) { FILE *file1_p; *indexFileName = NULL; int len = strlen(database); *indexFileName = (char *)malloc(len *sizeof(char) + 1);...

free() and mxFree() in MATLAB - freeing memory twice

Good day, I have the following code which has given me problems for a day already. I have debugged it, and it works fine until trying to free the memory. The free() function should be called at the end of the execution automatically, so I commented the mxFree() code out,...

C# apps using ram and cannot be cleared

Okay, i had create an apps and the apps are eating ram too much. The Problem: At the clearing process, i dispose the object but the ram usage isn't going down I don't have any idea, where is the mistake. How the program works Started user press space -> screen...

Using a data pointer with CUDA (and integrated memory)

I am using a board with integrated gpu and cpu memory. I am also using an external matrix library (Blitz++). I would like to be able to grab the pointer to my data from the matrix object and pass it into a cuda kernel. After doing some digging, it sounds...

Is BitSet worth using?

I made a Java object that has a lot of Boolean fields. I was considering using BitSet when I started questioning its usefulness. Of course, one would use it for memory reasons, since a boolean is 8 bits alone, 4 in an array. With BitSet, each value is stored as...

Is there a difference between new List() and new List(0)

Is there a difference between new List<T>() and new List<T>(0) ? May be this is a micro-optimization, but the idea is to understund the difference in term of memory allocation....

Fast memory allocation for real time data acquisition

I have a range of sensors connected to a PC that measure various physical parameters, like force, rotational speed and temperature. These sensors continuously produce samples at some sample rate. A sample consists of a timestamp and the measured dimension itself; the sample rates are in magnitudes of single-digit kilohertz...