alessandro
i have one file, it has like 400 names, which is the best way to manage it in memory? I mean if I can manage it in one program without lose performance?
Anonymous
Can you tell me how to create a profile account for a game like minesweeper?
Anonymous
In c
alessandro
idk
Zel
@Alex0162080 Best way is to not have 400 copies. Load it once and use pointers to acess it.
alessandro
@Alex0162080 Best way is to not have 400 copies. Load it once and use pointers to acess it.
ok, but is there possibility my program become slowly when it will try search data?
Zel
@burn Slightly, but that's like the text book case use for pointers, where as if you load the file 400 times it will be slow, memory intensive and possibly cuase dara loss if you are doing write operations.
Zel
Now on the flipside if you have 400 copies of exactly the same file on disk, you may want to optimize how you are using data.
Uliana
Please explain, how to delete structure components, while working with files, cause I think I’m doing all right, but it doesn’t work(C language)
Dima
use fclose() and null its file pointer
Uliana
I use them) but nothing happens
Dima
you better post the code using pastebin
Uliana
I’m sorry, but what is pastebin?😳
shriman_deepak
I’m sorry, but what is pastebin?😳
Google pastebin, u paste ur code there and share the link here,
Ибраги́м
https://www.youtube.com/watch?v=xBAduq0RGes
Denys
Hm, isn't sstream C++ library?
It is C++ lib but l am using C and graphics.h. Its my second project using it and in my first all work without any problem
Ибраги́м
Deepak Chaurasia
Hay like i am trying to make a char type array of length 100 so is it possible to check on how much memory occupied Like char arr[100] I enter the string "the " So it can return 3 byte occupied
Deepak Chaurasia
strlen
Not like that, like this is boy so i need to print something like that This is Boy
Deepak Chaurasia
So i need index of all words to print in new line from a string
Anonymous
Do you have the code for dividing two long numbers?
Deepak Chaurasia
Do you mean to factorial?
\Device\NUL
Not like that, like this is boy so i need to print something like that This is Boy
You must using OS API directly, like windows console API ReadConsole or POSIX read syscall. edit: there's fread function which is similar to read
Uliana
https://pastebin.com/MYmZrLw0
shriman_deepak
https://pastebin.com/MYmZrLw0
And what is the problem with ur code ?
shriman_deepak
And i see in line 69, if u are trying to delete the data which is already there in the file then u should use == 1 instead of 0 coz.. 0 means false and 1 means true.
Uliana
and I can’t delete
shriman_deepak
well send me the text file u are working on
.
Which one is better? Mingw or cygwin?
.
I'm a newbie
Chat Boss
Aurora YxY sent a code, it has been re-uploaded as a file
Aurora
prompt segment fault
Aurora
AllocPageMem is allocate shared memory function by mmap
alessandro
I'm a newbie
If you can use windows you could begin with visuale studio community, it include c++ compiler....
MᏫᎻᎯᎷᎷᎬᎠ
I just found out there is a feature called function-try-block in C++, wow this languages never cease to surprise me Anyway I'm checking it in cppreference It states: Reaching the end of a catch clause for a function-try-block on a destructor also automatically rethrows the current exception as if by throw;, but a return statement is allowed. What does this mean, the last sentence I know it's not possible return something from the destructor
Anonymous
I just found out there is a feature called function-try-block in C++, wow this languages never cease to surprise me Anyway I'm checking it in cppreference It states: Reaching the end of a catch clause for a function-try-block on a destructor also automatically rethrows the current exception as if by throw;, but a return statement is allowed. What does this mean, the last sentence I know it's not possible return something from the destructor
Try this program : https://pastebin.com/4svQNeW2 Now uncomment the return in the destructor catch clause and try it again. The return statement referred to there is not a return from the destructor but a return from the catch. Destructor s are implicitly marked noexcept. An exception propagated out of a function try block around a destructor will terminate your program. If you have a valid use case where you want to suppress this behavior, you don't let this exception propagate by using a return from the catch statement.
MᏫᎻᎯᎷᎷᎬᎠ
Why function-try-block is used rarely, I think It's great, is there any drawbacks?
Anonymous
Why function-try-block is used rarely, I think It's great, is there any drawbacks?
It is just like any other feature. Has its uses. It is used where it ought to by people who know about it. Mostly used to catch exceptions in the member initializer list of a constructor. Seldom used around a destructor unless you have a custom allocator and you allocate specific chunks of an instance of a specific type. It is not used outside of these two use cases.
DaviChan
Why function-try-block is used rarely, I think It's great, is there any drawbacks?
- Its "modern". Many code bases are still using old code pre C++11 and it takes time to adapt. Also checking error codes does also work well. In C++ we have multiple ways to deal with exceptions, so this one is not always preferred. - comes with runtime overhead. - disturbes control flow, might make code flow hard to follow But yes, it is a great feature to have and for some projects i even abused them to an extend because its easy to work with.
DaviChan
For example at our comapny we use C++20, we still don't use try blocks. Not sure why. But you can clearly tell code that was written recently from old code appart. We do still have code from unix times where functions that really should be void return a bool or int as a status code that no one ever checks
Anonymous
- Its "modern". Many code bases are still using old code pre C++11 and it takes time to adapt. Also checking error codes does also work well. In C++ we have multiple ways to deal with exceptions, so this one is not always preferred. - comes with runtime overhead. - disturbes control flow, might make code flow hard to follow But yes, it is a great feature to have and for some projects i even abused them to an extend because its easy to work with.
<quote> Its "modern". Many code bases are still using old code pre C++11 and it takes time to adapt.</quote> Are you sure you are talking about function try blocks? Function try block has been available in C++ since C++98. It was not introduced in C++11 <quote>Also checking error codes does also work well. In C++ we have multiple ways to deal with exceptions, so this one is not always preferred.</quote> You can't convey error codes to calling code from a constructor if an exception gets thrown in the member initializer list. The function try block is meant to address this issue. There is no alternative way to handle this. <quote>- comes with runtime overhead.</quote> Like I said, there is no other way to address this issue. And there will be an overhead only when an exception is thrown and not otherwise. <quote>- disturbes control flow, might make code flow hard to follow</quote> On the contrary, in general exceptions make code easier to read by separating out the error handling case from the actual code where the error occurs. It has an overhead compared to things like error codes but has other advantages over them. <quote>But yes, it is a great feature to have and for some projects i even abused them to an extend because its easy to work with.</quote> I think you have no idea what he is asking about. Please tell us how you abused them.
Ludovic 'Archivist'
<quote> Its "modern". Many code bases are still using old code pre C++11 and it takes time to adapt.</quote> Are you sure you are talking about function try blocks? Function try block has been available in C++ since C++98. It was not introduced in C++11 <quote>Also checking error codes does also work well. In C++ we have multiple ways to deal with exceptions, so this one is not always preferred.</quote> You can't convey error codes to calling code from a constructor if an exception gets thrown in the member initializer list. The function try block is meant to address this issue. There is no alternative way to handle this. <quote>- comes with runtime overhead.</quote> Like I said, there is no other way to address this issue. And there will be an overhead only when an exception is thrown and not otherwise. <quote>- disturbes control flow, might make code flow hard to follow</quote> On the contrary, in general exceptions make code easier to read by separating out the error handling case from the actual code where the error occurs. It has an overhead compared to things like error codes but has other advantages over them. <quote>But yes, it is a great feature to have and for some projects i even abused them to an extend because its easy to work with.</quote> I think you have no idea what he is asking about. Please tell us how you abused them.
Also, exceptions are not modern, expecteds are the modern alternative for unexceptional erroneous behaviors
DaviChan
<quote> Its "modern". Many code bases are still using old code pre C++11 and it takes time to adapt.</quote> Are you sure you are talking about function try blocks? Function try block has been available in C++ since C++98. It was not introduced in C++11 <quote>Also checking error codes does also work well. In C++ we have multiple ways to deal with exceptions, so this one is not always preferred.</quote> You can't convey error codes to calling code from a constructor if an exception gets thrown in the member initializer list. The function try block is meant to address this issue. There is no alternative way to handle this. <quote>- comes with runtime overhead.</quote> Like I said, there is no other way to address this issue. And there will be an overhead only when an exception is thrown and not otherwise. <quote>- disturbes control flow, might make code flow hard to follow</quote> On the contrary, in general exceptions make code easier to read by separating out the error handling case from the actual code where the error occurs. It has an overhead compared to things like error codes but has other advantages over them. <quote>But yes, it is a great feature to have and for some projects i even abused them to an extend because its easy to work with.</quote> I think you have no idea what he is asking about. Please tell us how you abused them.
Didnt know this feature is that old lol. I thought it got added in c++11 thanks. Yes vaild point! On the taking out the error handling from the function I can only partially agree. You can throw anything to anywhere in C++ and this can get messy more quickly in my opinion. What is easy to read ofc. also is preference/what you are used to. You can use them to test anything. Not only as exception hander. What to test if a file exists?: Just try to read from it return true in the try block, return false in the catch block.... ofc. this is a dumb example, but you can get very creative with that.
DaviChan
But yeah... i never used try catch until C++11... why are they so unpopular 😅🤔
DaviChan
I mean java and python guys use it all the time
DaviChan
will look into that later :)
...
"exceptions" under modern OS's can get very cumbersome, look at MSVC's SEH extensions for example, absolute chaos
...
will look into that later :)
https://gcc.godbolt.org/z/hszaWqE5n here, this should serve as a good enough starting point
Totti
How to create a structure type
DaviChan
How to create a structure type
struct a{/*...*/}; uhm like that?
DaviChan
you can use a typedef or write it like this: struct{/*...*/} a; to be able to use it without the "struct"
Gabriel
struct some_data { int x; int y; };
DaviChan
Yeah the comment looks cute right 👌😂
...
Thanks, i use this tool daily ^^
I meant the code that this links to, you can see a lot of unnecesarry calls & GCC's optimizer esentially giving up on optimizing away the function call
Gabriel
You could try something like typedef struct vector_region { float x, y, z; } vector_t; And uses the "vector_t" as type when defining the variable
Totti
Thank you guys
Ludovic 'Archivist'
But yeah... i never used try catch until C++11... why are they so unpopular 😅🤔
Because while exceptions are (almost) free if they are not thrown, if thrown, the stack unwinding is very very expensive. They should be kept for very exceptional/dramatic errors and not for what I would describe as common errors (errors that may happen more than 100 times per second are common enough in my book, errors that may happen once a second at most are not)
Anonymous
Can anyone suggest best c++ video playlist on YouTube.
Deepak Chaurasia
What are you trying to do
Anonymous
I got an exercise in c language, asks for making the "mine swipper" game anyone here can help me?
Anonymous
The problem is not making the game it self , I got the c files and header but how to complete it.... So if anyone can help I Ppreciated
klimi
The problem is not making the game it self , I got the c files and header but how to complete it.... So if anyone can help I Ppreciated
i would say that if you don't know how mineswipper works, you can firstly learn that, after you know that it is quite easy to implement
Ar
const char* shader = “#version 330 core\n” “layout (location = 0) in vec3 aPos;\n” “void main()\n”
Ar
Why can pointer be assigned certain strings?
touhou
Why can pointer be assigned certain strings?
String here is just an array of characters. When you do something like that above statement. The pointer will just point to the first character in the array. i.e addr of the first element is stored in the pointer. But you cannot modify that string tho.
touhou
Or I would even say, don't even consider it as an array. It's just characters in continuous block of memory.
touhou
touhou
To make it more clear to read or whatever.