𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, given the following code: int shmid= shmget(key, SIZE, 0666); char *addr= shmat(shmid, 0, SHM_W); // Optional code here; shmdet((const void *) addr); Should I use free(addr) after detaching my shared memory from the current addres space?
Anonymous
Hi guys, given the following code: int shmid= shmget(key, SIZE, 0666); char *addr= shmat(shmid, 0, SHM_W); // Optional code here; shmdet((const void *) addr); Should I use free(addr) after detaching my shared memory from the current addres space?
No. Shmdt detaches the shared memory from your address space which is good enough. However you can still reattach the shared memory to your process's address space later. If you don't want to reattach it, you should call shmctl. You don't have to call free.
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
thank you very much!
Steven
thank you very much!
basic rule: malloc/free should match
Thadeu
/get cbook
Anonymous
/get
Oumayma
hello every one i want to ask someone who has an experience in js i find it difficult . how can i learn it pls
Oumayma
i mean i want the good way to learn it
Ramil
First if all you shouldn't even touch JS, that thing is cursed. Secondly, I am sorry but this is a C/C++ board.
Null
After all same?
No syntax is also incorrect
Ольга
*confused nick young. Isn't when reading input is inputting into string ? Just iterate the string and check the ASCII value
I'm sorry but I've been learning this for exactly two days. In assembler numbers are perceived separately like I see 999 and I just need to go through this as a line and it will find these three nines ???
Ramil
Is there anyone here who is good at math?
Literally studied my entire life
Ludovic 'Archivist'
etrn1ove
Does someone know boost asio at good level? I have a couple of questions.
Ludovic 'Archivist'
dontasktoask.com
Ramil
dontasktoask.com
you must be getting tired of sharing the same link xd
Ludovic 'Archivist'
you must be getting tired of sharing the same link xd
You can't imagine, people do not even read the http://www.catb.org/esr/faqs/smart-questions.html in the rules
Aristo
https://cdecl.org/
Ludovic 'Archivist'
I mean reading is kinda boring sometimes ngl.
Yes, just like the non-questions that it answers
Ramil
Yes, just like the non-questions that it answers
Yeah, I wish we could read each other's mind, that wouldn't cause any problems
Ludovic 'Archivist'
Yeah, I wish we could read each other's mind, that wouldn't cause any problems
Well GUESS WHAT, we have a tool for that called language that people have spent the last centuries pulling appart to prove that it can express anything with only mild levels of ambiguity
Ludovic 'Archivist'
eh, fair enough, can't argue with that
Don't try or I'll need to quote 5 dozen linguists and take psychic damage for it
محمد
Hi i need help Need a solution to the exercise?
Michel
Hi, I had a look at it, I see you don't have the previous issue reproducible, but running valgrind showed me another one in derivative_Chebyshev_T, you have new and delete for an array, but there's a possible return in-between that may resulting in not calling that delete and memory leak. Looking at this part of code and other parts it seems that you not really using RAII, which is one of the most important features of C++. You can use gsl::finally, or write one yourself to call arbitrary cleanup code on scope end. Or if it's available to you, use std::vector, (with optimizations and exceptions disabled it doesn't have a lot of overhead), or if you're not sure you can just write a class that allocates memory in constructor, deallocates in desctuctor and has all copy/move deleted (or implemented, but then be careful with the implementations, e.g. your matrix implementation allocated in move constructor, which probably a lot of runtime overhead if you don't care about the moved-from object).
Yes, sorry, I didn't put a compatible input file in the repo for testing. Thanks for derivative_Chebyshev_T I didn't notice. I don't know what it RAII, I guess I'll read about it on cppreference.com or if you have a better source it'll be welcomed. I can't use the STL because once the code is complete I plan to translate it to CUDA and CUDA (at least the version I can use) doesn't support STL. About the move operator in Matrix2D I allocate one element of T with the default constructor so that the object on the other side gets something allocated so that its constructor doesn't try to deallocate something that wasn't allocated. I'm not sure if that's the best way to do it. Thanks a lot for your time and answers
● Igor
hi, i would like to know which algorithm std::sort uses... i was reading this and it mentions time complexity, but it doesn't seem to tell which algorithm it is https://en.cppreference.com/w/cpp/algorithm/sort
Anonymous
hi, i would like to know which algorithm std::sort uses... i was reading this and it mentions time complexity, but it doesn't seem to tell which algorithm it is https://en.cppreference.com/w/cpp/algorithm/sort
This varies from implementation to implementation. The libstdc++ provided by GNU uses introsort. Libc++ provided by Clang uses mergesort initially and then when the number of elements in the smaller arrays are less than a specified value, it reverts to insertion sort. https://en.m.wikipedia.org/wiki/Introsort
Pknatic
☹️
Michel
When I say: double array [n]; is this being allocated on the heap the same way new[] would?
Michel
In my case I can replace all the new[]/delete[] with objects of the Array I made
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Mmm I may be mistaken (I'm a beginner), but from what I understood, in this way you know at compile time the dimension of the array, and if it's not too enormous it should be on the stack. Things are allocated on the heap when you do something like double *array; Because you don't know the dimension. But, again, I may be mistaken, so wait for someone more expert than me
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
I surely wrote some wrong things, if you could please correct me it would be useful for me, too
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Oh, so maybe I did understand something in class 😂
Michel
But I don't know how big the stack can be. In competitive programming it's common to see things like this: int MAXN = 1000; int G[MAXN][MAXN]; // do your stuff with the graph I guess such a big array needs to be allocated on the heap.
Ольга
Pavel
I'm using new[]/delete[] in some functions because I was getting a warning: ISO C++ forbids variable length array
You don't need variable size arrays (the ones that are not supported (VLA)), allocation on heap is OK, but just it usually good to hide it inside a class like std::vector or your Array class, not to forget to delete the array in all the places where it needed.
\Device\NUL
They common use nonsense unportable code like #include <bits/stdc++.h .
\Device\NUL
I wonder if they learn with -pedantic-errors enabled, because you will never know what os and arch used to test the code, so it's best to stick with standard
\Device\NUL
Windows NASM x64 and x86
https://stackoverflow.com/questions/8021772/assembly-language-how-to-do-modulo Actually i don't understand what you're talking about :<.
\Device\NUL
If it's reading from stdin and store it into string, just iterate until you find 0. and compare it one by one with ASCII value
Anonymous
Hello everyone
Pavel
Can I declare a binary arithmetic operator for a class that allows to multiply float to my class without using friend function? So myClass * someFloat and someFloat * myClass both will work
Pavel
Can I declare a binary arithmetic operator for a class that allows to multiply float to my class without using friend function? So myClass * someFloat and someFloat * myClass both will work
Ok, seems I can't, but in my case I can make it just a normal free function. Context: friend doesn't work together with [[nodiscard]], and clang complains about their combination
Bappah
, , ,
Anonymous
#include <iostream> using namespace std; int c; void & referance (){ return c; } int main(){ reference ()=20; cout<<"c ="<<c<<endl; return 0; }
Anonymous
# include <iostream> # include <math.h> using namespace std; /* Determine the armstrong nunber: 512= pow((5+1+2),3); */ int armstrong (int n) { int r,result=0; while (n>0) { r=n/10; result=result+pow(r+r+r,3); n=n/10; } return result; } int main () { int n; cout<<"n="; cin>>n ; if(n==armstrong(n)){ cout<<"this nunber is an armstrong number"; } else{ cout<<"this nunber is not an armstrong number"; } return 0; }
Anonymous
Can I use arthematic operator with if statements ?
Anonymous
#define BACKLOG 5 class TcpServer{ public: TcpServer(int port) : _port(port), _sock_listen(-1) {} ~TcpServer(){ } public: bool InitTcpServer(){ _sock_listen = socket(AF_INET, SOCK_STREAM, 0); if (_sock_listen < 0){ std::cerr << "socket error!" << std::endl; return false; } struct sockaddr_in local; memset(&local, 0, sizeof(local)); local.sin_family = AF_INET; local.sin_port = htons(_port); local.sin_addr.s_addr = INADDR_ANY; if (bind(_sock_listen, (struct sockaddr*)&local, sizeof(local) < 0)){ std::cerr << "bind error" << std::endl; return false; } if (listen(_sock_listen, BACKLOG) < 0) { std::cerr << "listen error" << std::endl; return false; } return true; } void Loop(){ while (true){ struct sockaddr_in peer; socklen_t len = sizeof(peer); int sock = accept(_sock_listen, (struct sockaddr*)&peer, &len); if (sock < 0){ std::cerr << "accept error" << std::endl; continue; } std::cout << "get a new link : " << sock << std::endl; } } private: int _port; int _sock_listen; };
Anonymous
i want to know why can't accept successful
Anonymous
The function "Loop" can't work, just all time to run "accept error"
Pavel
Are there any drawbacks of including headers that are already added to precompiled headers file? I guess only preprocessing time will be affected that should be not really noticeable?
Pavel
Errors maybe? Duplication hence compilation time.And why should you when you know this?
Some tools like clang analyser assume headers are compilable by themselves (which usually should be true if there are no precompiled headers)
Pavel
So to use them I need to include all the headers needed (or forward declare the used types)
רז
hi , looking for help with strtok_s function on c, any 1 can help?
G.E.N.E
Hello
G.E.N.E
#include <iostream> #include <conio.h> #include <math.h> #include <iomanip> using namespace std;   const float PI=3.14159265358979323 const float n=0.2032; float area(float dia) { return PI*dia*dia/4; } Int main() {             float pipel[2][4],piped[2][4],pipeqass[2][4],vel[2][4],hf[2][4],hfbyq[2] [4] ,delq[2][4],delq1,d elq2,qdash[2][4],sighf[2]={0,0},sighfbyq[2]={0,0};             int common[2][4];             float qpn,dp4,cpn;             for(int i=0;i<10;++i)             {                         cout<<"\nENTER THE VALUES OF PIPE IN LOOP"<<i+1;                          for(int j=0;j<10;++j)                          {                                      cout<<"\nPIPE NO"<<j+1;                                      cout<<"\nPIPE LENGTH(in m):";                                      cin>>pipel[i][j];                                      cout<<"\nPIPE DIAMETER(in mm):";                                      cin>>piped[i][j];                                      cout<<"\nIS IT A COMMON PIPE?(1-YES,0-NO)";                                      cin>>common[i][j];                                      cout<<"\nFIRST ASSUMED VALUE OF Q(in m^3/min)";                                      cin>>pipeqass[i][j];                          vel[i][j]=(pipeqass[i][j]/60)/area(piped[i][j]/1000);                          qpn=pow(pipeqass[i][j]/60,n);                                      if(pipeqass[i][j]>=0)                                      {                                      dp4=pow(piped[i][j]/1000,4.87);                                                  cpn=pow(100,n);                                      hf[i][j]=10.622*(pipel[i][j])*(qpn)/(cpn*dp4);                                      hfbyq[i][j]=hf[i][j]/pipeqass[i][j];                                                  if(i==0)                                                  {                                                              sighf[0]+=hf[i][j];                                                      sighfbyq[0]+=hfbyq[i][j];                                                  }                                                  if(i==1)                                                  {                                                              sighf[1]+=hf[i][j];                                                      sighfbyq[1]+=hfbyq[i][j];                                                  }                                      }                                      else                                      {                                                  dp4=pow(-piped[i][j]/1000,4.87);                                                  cpn=pow(100,n);                                      hf[i][j]=10.622*(pipel[i][j])*(qpn)/(cpn*dp4);                                      hfbyq[i][j]=hf[i][j]/pipeqass[i][j];                                                  if(i==0)                                                  { sighf[0]+=hf[i][j]; sighfbyq[0]+=hfbyq[i][j]; } if(i==1) { sighf[1]+=hf[i][j]; sighfbyq[1]+=hfbyq[i][j]; } } } delq1=-sighf[0]/(n*sighfbyq[0]); delq2=-sighf[1]/(n*sighfbyq[1]); } for(int i=0;i<10;++i) { for(int j=0;j<4;++j) { if(i==0) delq[i][j]=delq1; if(i==1)delq[i][j]=delq2; } } for(int i=0;i<10;++i) {for(int j=0;j<4;++j) { if(common[i][j]) { if(i==0) delq[i][j]=delq1-delq2; if(i==1) delq[i][j]=delq2-delq1; } } } for(int i=0;i<10;++i) { for(int j=0;j<4;++j) { qdash[i][j]=pipeqass[i][j]+delq[i][j]; } } cout<<"\n\n\nITERATION 1\n\n"; cout<<"SNO LEN(m) DIA(mm) C ASSQ(m^3/min) ASSQ(m^3/s) VEL(m/s) Hf(m) Hf/Q(m/m^3/min) delq(m^3/min) qdash(m^3/min)"; for(int i=0;i<10;++i) { cout<<"\n"; for(int j=0;j<4;++j) { cout<<i+1<<" "<<pipel[i][j]<<" "<<piped[i][j]<<" "<<100< <" "; std::cout<<std::setprecision(4)<<pipeqass[i][j]<<" "<<pipeqass[i][j]/60<<" "<<vel[i][j]<<" "<<hf[i][j]<<" "<<hfbyq[i][j]<<" "<<delq[i][j ]<<" "<<qdash[i][j]; } } getch();  return 0; }
G.E.N.E
Who can help correct the code in C++
G.E.N.E
Very urgent
Nils
Very urgent
Saying that won't give you any faster response specially in communities. We're not paid. It's most likely only going to add some ignorance, therefore only delaying responses.