Code is causing segmentation fault when allocating memory or aborts program when freeing memory
Date : March 29 2020, 07:55 AM
wish of those help When I try to run my code, it causes segmentation fault on malloc on 89th line with "s1 = malloc(65536);" which persist even if I change it to calloc or realloc and also it causes this to be written if I have my function to free memory on line 82 or 86: , Consider one of your first tests with s_strcat(): s_init(&ss1, NULL, 8);
s_strcat(&ss1, &ss3);
if(array == NULL) {
str->length = num;
if(num != 0)
str->string = malloc(num);
for(i = destination->length, j = 0; j < source->length; i++, j++)
destination->string[i] = source->string[j];
for(i = 0; i < source->length; i++)
destination->string[i + destination->length] = source->string[i];
|
Allocating and freeing memory in a single kernel slower than Allocating in one then freeing in another
Date : March 29 2020, 07:55 AM
seems to work fine You're missing a pretty important point, and that is that the size of the device heap (from which device new or malloc receive their allocations) is limited. The default limit is 8MB. You can adjust this limit. (Read the documentation.) Your first allocation just happens to fit under the 8MB limit (==4MB) and therefore the allocation (requested by a single threadblock) is succeeding. Other threadblocks in that first launch are failing, and the remainder of your allocations are 8MB or larger, and are all failing. So all that data is not indicating what you think. if(t_data==NULL) return;
$ cat t482.cu
#include <iostream>
#include <string>
#define cudaCheckErrors(msg) \
do { \
cudaError_t __err = cudaGetLastError(); \
if (__err != cudaSuccess) { \
fprintf(stderr, "Fatal error: %s (%s at %s:%d)\n", \
msg, cudaGetErrorString(__err), \
__FILE__, __LINE__); \
fprintf(stderr, "*** FAILED - ABORTING\n"); \
exit(1); \
} \
} while (0)
__device__ int *D_DATA[1000];
__global__ void MyAllocate(int size,bool perform_delete) {
int *data;
__shared__ int *t_data;
if(!threadIdx.x)
t_data = new int[size];
__syncthreads();
if(t_data==NULL) {if(!threadIdx.x) printf("oops!\n"); return;}
if(!threadIdx.x) D_DATA[blockIdx.x] = t_data;
data = t_data;
memset(data,0,size);
__syncthreads();
for(int i = threadIdx.x;i < size; i+= blockDim.x)
data[i] = i * i + perform_delete * i;
__syncthreads();
// If we should delete then do so, otherwise another kernel (hopefully) will
if((!threadIdx.x) && (perform_delete))
delete data;
}
__global__ void MyDelete() {
delete D_DATA[blockIdx.x];
}
int main(int argc,char **argv) {
cudaEvent_t start,stop;
float time;
const std::string pre[2] = {"One Kernel ","Two Kernels "};
for(int size = 1000000; size < 100000000; size *= 2) {
cudaDeviceSetLimit(cudaLimitMallocHeapSize, 500000000);
cudaCheckErrors("set limit fail");
for(int i = 0; i < 2; ++i) {
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start,0);
MyAllocate<<<1,128>>>(size,i==0);
if(i!=0) {
MyDelete<<<1,1>>>();
}
cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);
std::cout << pre[i] << "Time : " << (time) << "ms" << std::endl;
cudaEventDestroy(start);
cudaEventDestroy(stop);
cudaCheckErrors("some error");
}
cudaDeviceReset();
std::cout << std::endl;
}
return 0;
}
$ nvcc -arch=sm_20 -o t482 t482.cu
$ ./t482
One Kernel Time : 139.846ms
Two Kernels Time : 139.37ms
One Kernel Time : 280.762ms
Two Kernels Time : 274.804ms
One Kernel Time : 559.386ms
Two Kernels Time : 549.536ms
One Kernel Time : 1101.04ms
Two Kernels Time : 1114.58ms
One Kernel Time : 2199.96ms
Two Kernels Time : 2229.1ms
One Kernel Time : 4397.82ms
Two Kernels Time : 4458.15ms
One Kernel Time : 8793.6ms
Two Kernels Time : 8916.23ms
$
|
What can be the reason on why the C program is not freeing up the memory even after closing the files and freeing the po
Tag : c , By : SpittingCAML
Date : March 29 2020, 07:55 AM
To fix this issue The following function is being called multiple times from the main function. I am monitoring the RAM usage of the program. Every time a call is being made to this function the RAM memory usage increases. The problem is every time the function terminates and I close the file, the RAM memory usage still keeps on increasing. So, after a few calls to this function the system kills the process because of using too much memory. Can you please help me with this problem? , With the lines: char **track_path = (char **)malloc(MAX_NODE * sizeof(char *)); // Array of strings which contains the track path diverging from a specific output (ii th output)
for(int i = 0; i < MAX_NODE; i++)
{
track_path[i] = (char *)malloc((100) * sizeof(char));
}
free(track_path);
for(int i = 0; i < MAX_NODE; i++)
{
free(track_path[i]);
}
free(track_path);
|
Freeing memory with delete vs smart pointer and proper way of freeing memory
Tag : cpp , By : Chris Tattum
Date : March 29 2020, 07:55 AM
I wish this help you I'm doing a project for the university and im trying to find out how to delete memory properly and if the way of deleting that i came up with will have the same effect as using smart pointer. , Is this a proper way of freeing the memory employees.push_back(new Employee());
teams.push_back(new Team());
void someFunction()
{
Company c;
// stuff...
} // the scope ends here, ~Company will be called
|
Two pointers are pointing to same memory address, how to avoid memory leak in case freeing of these two happens at indep
Tag : c , By : user183676
Date : March 29 2020, 07:55 AM
|