Ehsan
you use CMAKE to build the projects
Ehsan
CLion just run it
Prince Of Persia
Prince Of Persia
but CLion needs to read the file which included to the project
Prince Of Persia
and this makes it slow
Ehsan
you can choose to run the release or the debug version of the executable :_)
Ehsan
???
if you want to run fast, run the release version of the executable
Prince Of Persia
I have no problem in creating apps my problem is only in speed of analysis of CLion
Prince Of Persia
Prince Of Persia
ok
can you help?
Ehsan
can you help?
if speed of “analysis” is not good with CLion you can do it with the terminal
Ehsan
you have external terminal in clion or you can open a new terminal
Prince Of Persia
can I boost analysis?
Ehsan
can I boost analysis?
with the terminal? yes you can
Prince Of Persia
with the terminal? yes you can
can I send you a picture in your DM?
Anonymous
Differences between std::endl and “\n” please???
std::endl forces a file flush. Typically "\n" will too but endl guarantees so.
PO
HI Someone can explain to me how to write a getter funtion in c for a 2d array which is in a structure, please?
PO
You need to be more specific.
i have a structure which in pnm.c , I allocated memory, at the end I have to free() the momory which was allocated in main.c. In my structure I have a 2d matrix, to free the memory which was allocated for my 2d array, I made a function and in this function i need the nomber of raw and acces to the matrix(2d array) so I wreated 2 getter function which works with geeting nomber of raw. but it give a seg fault when I want get 2d array
PO
it’s probably because you tried to derefrence uninitiliazed pointer
I don't exactly how should i make a getter function for 2d arra
Ehsan
I don't exactly how should i make a getter function for 2d arra
it depends on how you implemented the 2d array
PO
it depends on how you implemented the 2d array
/* * get_matrix * @pre: ptr != NULL * @post: matrix getter for opaque type structur */ unsigned int** get_matrix(PNM *ptr){ assert(ptr != NULL); return ptr->matrix; }
PO
it depends on how you implemented the 2d array
struct PNM_t { unsigned int imageFormat; unsigned int raw; unsigned int column; unsigned int colorValue; unsigned int **matrix; };
Ehsan
**matrix is a pointer to a pointer
Ehsan
it’s not 2d array 🙂
PO
It's the worst idea ever to store image as uint**
it's the only to do that i think
Vlad
it's the only to do that i think
Yet every graphics api has textures stored as contiguous memory
PO
what does it mean?
Ehsan
what does it mean?
int matrix pointer
PO
I'm begginer to C
Ehsan
ok unsigned int *matrix the same:)
PO
My program open file and scan a matrix
Ehsan
so the simplict implementation I can think of is you allocate double the memory you would need(since it’s 2x2 matrix)
Ehsan
unsigned int *matrix = malloc(sizeof(int) * NUMOFELEMENTS * 2);
PO
wait
PO
before that I free the memory in fonction write() which is in file pnm.c but my teacher told me I can't chnage the return type of function write(), and he told i have to get free the memory in main() which in main.c
PO
static void destroy(unsigned int **destroy, unsigned int raw){ assert(destroy != NULL && raw > 0); for(unsigned int i = 0; i < raw; i++){ free(destroy[i]); } free(destroy); }
Vlad
uint32_t* texture = malloc(N * M * sizeof(*texture)); uint pixel = texture[i * M + j]
Ehsan
then to access an element(to read or write) you can make a simple access like this: unsigned int access(int *matrix, int row, int column){ unsigned int offset = length of row * row + column ; return matrix[offset]; }
PO
uint32_t* texture = malloc(N * M * sizeof(*texture)); uint pixel = texture[i * M + j]
I don't have any problem with malloc function because when I put i comment my destroy() function program works
Ehsan
what do you mean by offset?
do you how malloc works 🙂
Ehsan
and how memory is allocated?
PO
and how memory is allocated?
unsigned int **matrixPointer = malloc(raw * sizeof(unsigned int *)); if(!matrixPointer){ printf("creat_matrix : Memory Allocation Faield For Creating Matrix\n"); return NULL; } for(unsigned int i = 0; i < raw; i++){ matrixPointer[i] = (unsigned int*) malloc(column * sizeof(unsigned int));
Ehsan
https://en.wikipedia.org/wiki/C_dynamic_memory_allocation
Ehsan
you need to understand the basics first
Ehsan
then we will talk
Ralph
Hello
Ralph
Can someone tell me if i can optimize my code?
PO
do you how malloc works 🙂
All program works perfectly until my teacher sayed i have to use my destroy_matrix() function in main function. but in main.c i don't have access to my structure because my structure is inside an other file so I have to make getter
Ralph
Thanks
Ralph
template <typename Iter> int brute_max_sum(Iter start, Iter end) { auto max = (*start); max = 0; auto sum = (*start); sum = 0; for (; start != end; start++) { for (Iter fin = start; fin < end; fin++) { for (Iter inter = start; inter <= fin; inter++) { sum += (*inter); } if (sum > max) { max = sum; } sum = 0; } } return max; }
Ehsan
and what’s the problem?
PO
when I use "destroy(get_matrix(image), raw);" i get seg fault
Ehsan
that’s because you access illegal address
PO
destroy() function, it frees memory which was allocated for my matrix
Ehsan
https://pastebin.com/
Ehsan
paste your code here
PO
paste your code here
all of that? just the part which cause seg fault?
PO
because there is 4 file
Igor🇺🇦
Someone got this?
You didn't ask anything. 🤷‍♂️
Ralph
You didn't ask anything. 🤷‍♂️
If i can optimize it, type it in another manner, simpler
Igor🇺🇦
If i can optimize it, type it in another manner, simpler
What are you trying to do in this method?
Ralph
I have a function above for divide and conquer, and that function i sent is for the exhaustive result
Ralph
I am trying to get the answers faster, smaller duration
Igor🇺🇦
The First obvious thing is a weird use assignment with auto and assigning 0 on the next line