Most voted "allocation" questions
Allocation refers to interpreted languages such as C and C++, which dynamic memory allocation is part of data management and security.
Learn more…152 questions
Sort by count of
- 
		23 votes1 answer9539 viewsWhat is the difference between "calloc()" and "malloc()"?What the function calloc() makes the malloc() Doesn’t it? Why is it hardly used? 
- 
		11 votes3 answers1211 viewsConcepts of Mesomorphic Allocation and Liberation in C#I’m making a web application that has a finite recursive loop. But during the process the memory consumption is constantly growing and at the end Visual Studio has more than 2 Gigas of memory use. I… 
- 
		11 votes2 answers462 viewsHow to allocate dynamically when I don’t know how many positions I will use in C?In a part of the code I need to transform an integer into binary and store it in a character array, however, I don’t know which integer I will receive to transform into binary, so I don’t know how… 
- 
		10 votes3 answers42472 viewsError Segmentation fault (core dumped)I’m getting the following error message in my code: Segmentation fault (core dumped) Another thing is, when I performed the same function operation preenche in the main, using ficha.name in place of… 
- 
		10 votes2 answers158 viewsWhat happens to memory when "realloc()" reallocates a memory block to a value less than the original?Suppose I allot a dynamic matrix of 10 ints and assign some values values to it, then I use the function realloc() to reallocate the matrix to 3 ints, what happens to the other 7 ints, they will be… 
- 
		9 votes2 answers1582 viewsWhat is the difference in the syntax ptr = (int*) malloc (sizeof(int)) and ptr = malloc (sizeof(int))?I have a question about dynamic allocation in C. At the time of allocating memory I have seen these two types of syntax: ptr = (int*) malloc (sizeof(int)); ptr = malloc (sizeof(int)); But I don’t… 
- 
		8 votes3 answers747 viewsIs malloc typecast recommended?I have read that it is not advisable to do the Typecast of malloc when we are allocating memory to a new pointer variable, and many websites and books teach this practice in memory allocation, it… 
- 
		7 votes1 answer767 viewsChange of char variable contentI’m having trouble working with files and handling char. CODE char *fileTipoDespesaDefault; char *fileTipoPagamentoDefault; FILE *fileTipoDespesa; FILE *fileTipoPagamento; /** * tipos : 1 =>… 
- 
		7 votes2 answers330 viewsDynamic allocation and runtime of functionsWhen we use any of the dynamic allocation functions in C (malloc, calloc, realloc, etc.), within a function that is called by main, will the memory remain allocated at the end of the execution of… 
- 
		7 votes1 answer566 viewsDynamic Memory Allocation X vectorI was studying this subject in C, and in most of the places I look for, one of the examples of using this resource is when you’re going to create a vector whose size you don’t know. Example: int… 
- 
		6 votes2 answers830 viewsHow to allocate program memory and storage before running my application in Wince?I am reprogramming a C# application to run on Windows CE, but my machine has little memory. Therefore, I need to allocate the appropriate amount of processing memory (program memory) and storage… 
- 
		6 votes2 answers2673 viewsHow big is a memory address?What size of a memory address? I think a memory address has 32 bits, but I’m seeing it in a Debugger one int, where he separated 4 addresses for him. So, an address is equal to 32 bits? Because… 
- 
		6 votes2 answers475 viewsMalloc improperly reserving memory?I am studying dynamic memory allocation and came across an error that apparently the compiler is not warning about. The code is very simple: int *ptr = (int *) malloc(sizeof(int)); ptr[0] = 5;… 
- 
		6 votes1 answer217 viewsWhat is behind the malloc() dynamic allocation function?What mechanisms the function malloc() uses in practice to manage dynamic memory allocation in a program? 
- 
		6 votes1 answer80 viewsHow long is the data allocated to functions?In one language, (I don’t know if there’s any difference in others, but you can consider Javascript) when I have this situation: function a() { b(); } function b() { c(); } function c() { d(); }… 
- 
		6 votes2 answers146 viewsPointer changes address when exiting functionWhen performing a dynamic allocation of a vector or matrix in C, the pointer for that allocation changes address when leaving the function, before it was pointing to the initial address of the… 
- 
		6 votes2 answers198 viewsstrcpy is merging numeric format with other charsI don’t know if I made myself clear in the title, but when using strcpy() to copy a char* to another when I put a format like this "teste" it works normally, but when I put a string 3 letter format… 
- 
		5 votes2 answers295 viewsWhy did a dynamic array work without the use of malloc()?Follow the code passage below: int main(void) { int tam, vet[tam]; printf("\ndigite tam: "); scanf("%d", &tam); return 0; } I didn’t know this worked, because I’m typing the vector size at… 
- 
		5 votes1 answer332 viewsProblems with dynamic allocationIn an exercise I need to make a record of a struct possibly declared as follows:. typedef struct Locatarios { char nomeLocatario[MAX_NOME]; int codigoLoc; float valorAluguel; } Locatarios; It is… 
- 
		5 votes3 answers540 viewsColo allocate a memory based on the size the user typedHow can I get it right after the user enters a string the program counts the number x of characters of this and allocate X bytes to it? I am not able to do it, I tried for example to make after the… 
- 
		5 votes4 answers456 viewsMemory allocation for pointersI’ve been reading and studying on pointers and came across the following quote in a book: "Although it is possible to use them as vectors, pointers do not have their own memory. You can only use… 
- 
		5 votes2 answers724 viewsDelete a space allocated by mallocFirst I allotted 6 spaces of 52 bytes belonging to a struct in memory: lista = malloc(6 * sizeof(registro)); In practice to access them via pointer is done: lista[0], lista[1], lista[2]... And how I… 
- 
		5 votes1 answer776 viewsAllocation Space for Mysql FieldsFirst I create the model in my application, then the Entity Framework generates the SQL for the table creation. The first statement generates a column with the type varchar(20), the second generates… 
- 
		5 votes1 answer1146 viewsDynamic stack - CI’m studying dynamic stack from the code below: #include <stdio.h> #include <stdlib.h> #define tam 50 // ---- Estruturas para os tipos… 
- 
		5 votes3 answers1148 viewsDynamic allocation in C - allocating without knowing the total amount of elementsI have a question about the dynamic allocation in c, as to the use of the function malloc(). If we take, for example, a case of registration of a full name, as we have no way of knowing the amount… 
- 
		4 votes1 answer329 viewsPointer of struct in CWhat happens is this, within the function ins_ult() I can change the value of root->data, but outside the function the value remains NULL. I’m passing the parameter the wrong way or using the… 
- 
		4 votes2 answers14165 viewsDynamic allocation for structI need to dynamically allocate space for a structure, but I am not able and I do not know my error is at the time of the statement or allocation, follow the functions consistent with the statement.… 
- 
		4 votes2 answers69 viewsHow should these variables end correctly without having a chance of memory Leak?What is the right way to use the free() in that case, where ls_options will contain several ls_buffer_send? char **ls_options = (char**) malloc (200*sizeof(char)); char *ls_buffer_send = (char*)… 
- 
		4 votes2 answers117 viewsHow do I use free() and return the same content?I wanted to use the free() in ls_retorna in the following function, how could you do it with the best way? char* MemCpyX(char *as_origem, int an_inicio, int an_quantidade) { char *ls_retorno =… 
- 
		4 votes1 answer1450 viewsManipulating batteries in CI’m a C beginner and I have the following exercise: The Parking Stationhere contains a single boulevard that guards up to ten cars. There is only one entry/exit in the parking lot, in one edge of… 
- 
		4 votes3 answers408 viewsUse free() without malloc()?May cause some problem in using the free() on a pointer that was not allocated with malloc() beyond the necessity itself? void funcao (int par) { char *palavra; if(par%2 == 0) { palavra =… 
- 
		4 votes1 answer1523 viewsCorrect use of free() in function?How to use function free() when it is used within a function, in that function Gero a dynamic vector and the function itself will be the return, example: int* copia(int *vet, int tam) { int i,… 
- 
		4 votes1 answer96 viewsWhy not give Segmentation fault when writing to a "char *" without allocating memory?My question is whether the compiler automatically allocates memory to the variable s1 char *s1; char s2[20]; //s1=(char*)malloc (sizeof(char)*20); s1="palavra1"; strcpy (s2,"palavra2");… 
- 
		4 votes2 answers267 viewsBehaviour of malloc(1) in CIf I use char *char_commandout = (char *) malloc(1);, the allocated byte will store the " 0" at position 0 of the vector or will allocate a space for the value I want to store (at position 0) and… 
- 
		4 votes2 answers501 viewsWhen to dynamically allocate memory?In C++ you can easily declare an object or variable like this: tipo_da_variável nome_da_variável; This type of statement is the easiest to use, but you can also use the new to dynamically allocate… 
- 
		4 votes2 answers522 viewsDynamic allocation of vectorsFollows the statement: Make a program that reads keyboard numbers and store them on one dynamically allocated array. The user will type in a sequence of numbers, no quantity limit. The numbers will… 
- 
		4 votes2 answers221 viewsHow to transform my code with static memory struct to C dynamics?The exercise asks me to read information in a file, being them, Cpf, name, email and age of several people store in a struct, order in ascending order by age, if equal ages by Cpf, and print in… 
- 
		4 votes1 answer38 viewsUse of delete in an abstract class pointerReading the book A tour of C++, in a section on memory leakage, when I came across 3 statements regarding the code below: The implementation of Smiley may fail to delete pointer to mouth. The… 
- 
		3 votes1 answer111 viewsDoubt in dynamic memory allocationIn the code below, release B memory also releases from A? int* A = new int[4]; int *B = A; delete[] B; 
- 
		3 votes1 answer218 viewsC++ Dynamic Pointer AllocationI am needing to create a protection routine in the removal function. Why it gives error when removing the last item? The function: // Remover o primeiro cliente void cadRemover(){ lista=ini; //… 
- 
		3 votes3 answers211 viewsProgram using malloc twiceWhy this program that divides a number into decimal notation, transforms it into binary notation and prints the number on the screen in the correct sequence (from bit most significant for the least… 
- 
		3 votes2 answers1697 viewsRemove element from a chained listI am implementing a chained list of type "with head". It follows struct referring to the list and its creation in main() struct lista{ int info; struct lista *prox; }; typedef struct lista Lista;… 
- 
		3 votes2 answers176 viewsWhy am I getting Segmentation fault dynamic matrix?They say not to cast on the return of function malloc, but this code there if the dimension of the matrix is above 4, it gives Segmentation fault from matriz[5][1] in the count: int main(){ int… 
- 
		3 votes2 answers233 viewsError: "invalid operands to Binary Expression ('char *' and 'char *')"I need to create a string which contains "Mr: n" and the name of the person concerned (pessoa->nome). char* endereca(Pessoa* pessoa) { if(pessoa->sexo == 'M') { char *msg; msg =… 
- 
		3 votes1 answer75 viewsVector problem with dynamic allocationThe intention of this program that I am doing is to serve as if it were a banking system in which the amount of accounts to be created does not have a previously defined amount. In the main(), i… 
- 
		3 votes1 answer202 viewsProblem with dynamic allocation - realloc()I’m doing a program that works as a payroll system, but I’m having trouble with the dynamic allocation part. The program runs only once and stops. No int(main) i put: printf("Sizeof :… 
- 
		3 votes1 answer62 viewsProblems with dynamic matrix allocationI’m trying to dynamically allocate a matrix, but I’m having some problems with running time and I’m also getting a Warning of GCC in the compilation time. Follow the code below for a better analysis… 
- 
		3 votes2 answers84 viewsError of memory allocationI am creating a C script to classify a triangle according to the 3 sides passed. For this I use three distinct variables, lado1, lado2 and lado3, as illustrated by the code below: #include… 
- 
		3 votes1 answer111 viewsHow to allocate in contiguous memory a structure that contains 1 vector with user defined size?I was wondering how to answer this issue and I came to the conclusion that I would need a data structure with: the size of a set a previously reported size vector It would be something like the… 
- 
		3 votes1 answer125 viewsWhere does the memory space required for each element in a C string array come from?In C, you can group a set of string's, which are arrays of char's within a array without having to define 2 dimensions for this? That’s why you use a array pointer char's and simply defines the…