« first day (353 days earlier)      last day (2491 days later) » 
03:00 - 19:0019:00 - 00:00

3:57 AM
@Steephen Oh, thank you. Or you're welcome, whichever seems more appropriate.
 
 
4 hours later…
8:01 AM
good morning
 
8:18 AM
this video helped me understand pointers
and i tested that code and studied it for a while, and it works and i understand it
the code from yesterday
of the two handles
 
8:50 AM
when we create a template, can we know what type of data is entering the function?
wait let me explain in code
template <class data>
data (data x)
{
	std::cout << "x is an " << /*datatype of x*/;
}
is that possible?
so if x is a int, it says the data type of x
so int
 
9:13 AM
im having a error in the code, this is the code:
template <class T>
class exe {
	T first, second;
public:
	exe(T a, T b)
	{
		first = a;
		second = b;
	}
	T bigger();
};

template <class T>
T exe<T>::bigger()
{
	return(first>second ? first : second);
}
template <class T>
T exe<T>::smaller()
{
	return(first<second ? first : second);
}


int main()
{
	exe <int> eo(69, 105);
	std::cout << eo.bigger() << std::endl;
	std::cout << eo.smaller() << std::endl;
}
it gives me an error in eo.smaller()
when i call it
 
there is no smaller declared inside exe
 
the error says class "exe<int>" has no member "smaller"
 
then add it
 
but i declared it, no?
ohhh
 
@jeyejow no inside the class definition
 
9:14 AM
i need to do T smaller();
^ ??
inside the class
yep, that was it :p ty
im learning to use templates, they seem usefull
@ratchetfreak can you see if this sample code i made makes sence/works, it gives me no errors, but i might be doing something wrong, can i post it so you see?
BOOL Lock(HANDLE hDevice)
{
	BOOL bResult = FALSE;
	DWORD junk = 0;

	bResult = DeviceIoControl(
		hDevice,
		FSCTL_LOCK_VOLUME,
		NULL,
		0,
		NULL,
		0,
		&junk,
		(LPOVERLAPPED)NULL);
	return (bResult);
}


template <class T>
class process
{
	T devi1, devi2;
public:
	process(HANDLE d, HANDLE f)
	{
		devi1 = d;
		devi2 = f;
	}
	T close();
	T lock();
};
template <class T>
T process<T>::close()
{
	CloseHandle(devi1);
	CloseHandle(devi2);
}
template <class T>
T process<T>::lock()
{
	Lock(devi1);
^ goal of that code: lock 2 handles and close them
am i doing it right?
 
nwp
@jeyejow You are using the WinAPI. That is definitely not right.
 
hm?
i use this
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
i dont need the stdio.h or the wnioctl.h for this example i think
what is wrong with the WinAPI?
 
nwp
@jeyejow It is outdated and written in C. C++ has the things you use standardized to work everywhere with better interfaces.
 
9:29 AM
if what you need isn't the standard library then it's likely in one like Boost
 
work everywere? that makes no scene, this should only work in windows, linux doesnt treat devices like drives, but like files
nwp, so what do you recomend i use for what i am trying to do? i think the WinAPI works fine, what is your sujestion?
 
nwp
@jeyejow I don't really know what you are trying to do. Looks like a reimplementation of std::mutex to me. But generally use the STL. If that is not enough try boost or Qt or some other framework that does what you want directly.
 
@nwp what do you mean directly? im trying to create a HANDLE to a device and Close the handle, what am i doing wrong? why is using the WinAPI bad?
 
nwp
@jeyejow You only think that you want to create a HANDLE. You actually want to achieve something by creating that HANDLE and that something you want to achieve is easier to achieve without HANDLE.
 
@nwp what thing is that that im trying to achieve? please explain :o
 
nwp
9:38 AM
@jeyejow I don't know. You want to lock a device? Practice templates?
 
thats is to apply on my project
and the WinAPI is imo the best fit for it, because i need to use thoes functions to do what i want, which is writing do a file and writing to a device in Windows
unless you know a better way of doing that, and if you do, please tell me
 
nwp
Writing to a file is better done with std::ofstream. Writing to a device depends on the device.
 
@jeyejow what are you trying to do?
 
@BartekBanachewicz i mean, i can alreaddy do it, im just trying to make my code better, basicly im trying to mimic the linux command dd for windows
its a project i have :) its my first project
but windows doesnt read devices like files, so i have to use handles and all that
basicly read x bytes from device, copy them to file, and vice versa
so i can make usb backups in files and restore usbs with thoes files
 
nwp
so you want to make a clone of this
 
9:50 AM
@nwp
oops missclik
nwp, kinda yes
not exaclty, but kinda
its more or, copy a intire usb or parts of usb (i use a pointer in the bytes) to a file, so i can later if i lose that info in the usb i can run my program and it grabs the content in the file and puts it in the USB
i think its a nice idea
 
nwp
well the good news is that it comes with source code and has functions like
HANDLE getHandleOnFile(LPCWSTR filelocation, DWORD access);
HANDLE getHandleOnDevice(int device, DWORD access);
HANDLE getHandleOnVolume(int volume, DWORD access);
QString getDriveLabel(const char *drv);
DWORD getDeviceID(HANDLE handle);
bool getLockOnVolume(HANDLE handle);
bool removeLockOnVolume(HANDLE handle);
bool unmountVolume(HANDLE handle);
bool isVolumeUnmounted(HANDLE handle);
char *readSectorDataFromHandle(HANDLE handle, unsigned long long startsector, unsigned long long numsectors, unsigned long long sectorsize);
so you don't need to reimplement everything
 
can u link the source code?
so i can see what theyre functions do/ how they work
 
nwp
I don't know if there is a wrapper around winapi devices so you don't need to go through with the HANDLE stuff.
 
but i dont know anny way to do what i want exept with the use of HANDLES
i mean for the file i knwo, but for the device
ty
ill study their code
maybe ill learn new stuff
nope, they do the same thing im doing
they also use HANDLES and CreateFile and all that
maybe there is no way around it
 
but they wrap it in a nice portable interface (on linux they will be using file descriptors)
 
nwp
10:01 AM
@jeyejow Unfortunately it appears so. I would still advice you only use the WinAPI when there is no other way.
 
@nwp ok, ill take note, thanks! :D
how can i know the size of the disk and the left space on it
basicly, how can i know if the disk has enought space for me to store a file with x bytes
 
@Froglegs shiny
 
10:19 AM
@Froglegs so if i do this const char path = "C:\" and std::experimental::filesystemspace_info space(&path);
would this give me the space left in C: ?
 
i haven't used it, it appears to that is how it works yes
try it;0
 
oke!
yep, its works just fine
do this:
	std::cout << ".        Capacity       Free      Available\n"
		<< "/dev:   " << devi.capacity << "   "
		<< devi.free << "   " << devi.available << '\n'
oops miss clicke
1 sec
#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;

int main()
{
	fs::space_info devi = fs::space("C:");

	std::cout << ".        Capacity       Free      Available\n"
		<< "/dev:   " << devi.capacity << "   "
		<< devi.free << "   " << devi.available << '\n';
	getchar();
}
^ that worked for me, got the C: drive info i needed
thanks @Froglegs
 
@jeyejow bear in mind that older compilers won't support it
 
@BartekBanachewicz no? o.o how old?
like 2002 old?
or older?
 
@jeyejow the fs is gonna land in C++17 which isn't even released yet
 
10:33 AM
:V
 
so it's all hit-and-miss
 
well, is there annother way of getting the size of the C; drive? free space, left space, etc ?
 
@jeyejow only OS-specific. the fs aims to make it portable, so it's generally nicer, but again only if you're fine with being bleeding edge
if it's a hobby project then I'd do that obviously
 
nwp
boost::filesystem probably has something
 
you can fall back to using the boost version if for some reason you need to compile on an old compiler
 
10:35 AM
@BartekBanachewicz oh ok, ill have that in mind,, thanks!
using the boost library only to get the size of the C: ? is that recomended?
 
@jeyejow depends on who you ask
 
i mean, i never used the boost library, but i've heard its for alot of things
ic
 
if your goal is to ship resilient software, then you should write as little code as possible and then it's worth it to wait for boost compile times
 
its just a project of my own, so i guess i can stick with the fs
 
@nwp yeah there is a space(const path&) function in there
 
10:38 AM
can i find info of what the boost library alows me to do?
like a link with every function it has? if there is one?
i didnt find much on the boost page
 
boost is huge jey
 
hmm ic
 
each library in boost has a reference page
 
oke :v
is there a link for a boost::filesystem?
like @nwp mentioned
 
10:40 AM
thanks! @Froglegs
 
sorry thats a slightly old version
 
ty :D @ratchetfreak
 
Is there a faster alternative to std::partial_sort if I don't care about the order of the first n elements? nth_element followed by going through the container swapping pre-n and post-n values when necessary comes out slower than just using partial_sort
 
@Mirac7 try std::partition
 
11:02 AM
I would still need to run nth_element before partition, as I don't known the value of the n-th element beforehand
 
In computer science, quickselect is a selection algorithm to find the kth smallest element in an unordered list. It is related to the quicksort sorting algorithm. Like quicksort, it was developed by Tony Hoare, and thus is also known as Hoare's selection algorithm. Like quicksort, it is efficient in practice and has good average-case performance, but has poor worst-case performance. Quickselect and its variants are the selection algorithms most often used in efficient real-world implementations. Quickselect uses the same overall approach as quicksort, choosing one element as a pivot and partitioning...
aka pick a pivot and partition on that,
check size of each partition and select where n resides
repeat from step 1
 
11:23 AM
With both -O2 and -O3 flags it is within the margin of error compared to std::partial_sort. Going to stick with it, partial_sort is prettier to look at :D
Both implementations take 8.9-9.5us per run
 
 
2 hours later…
1:25 PM
hey is there an array type in c++? Take this example from c++-reference:
int (*ap)[2] = &a; // pointer to array of int

What changes if I'd write:
int (*ap)[10] = &a;
int (*ap)[] = &a;
int *ap = &a;
 
nwp
@milleniumbug is sleeping on the job
 
@Felix.C don't use built in arrays use std::array and std::vector instead
 
@ratchetfreak Thank for that advice, I'm learning for an exam and I'm trying to understand again how pointers and types work in C++.
 
4 messages moved from Lounge<C++>
@nwp fix'd
 
nwp
@Felix.C you should probably check what type a is
 
1:35 PM
xcode tells me:
int a[] = {1,2};
int (*ap)[] = &a;

Cannot initialize a variable of type 'int (*)[]' with an rvalue of type 'int (*)[2]'.
Is 'int (*)[x]' with x some number a type in C++?
thank you for the help
 
it's a pointer to some array with unspecified size
not very useful
 
why do teachers focus on this kind of crap? By the time you need a pointer to an array you have already put it into a struct and then you just point to the struct.
 
nwp
My theory is that teachers don't care about actual teaching. They care about forcing the students to study enough about various topics that interested students will keep studying on their own. The goal is to make students figure out what they are good at.
 
Ven
i'll take oversimplifications of a workforce for 500$, alex
 
goddamn strucks are so usefull
why didnt i knew about them
 
1:46 PM
and they haven't actually done any real programming in years and don't have the experience in real world programming to know that you just don't need that crap
 
2:03 PM
void message(int id) {
    std::lock_guard<std::mutex> guard(clients_mutex); // lock `clients` map, because we don't want to delete Client while its function isn't done, do we?
   clients[id]->update();
}

void close(int id) {
    std::lock_guard<std::mutex> guard(clients_mutex);
    clients.erase(id);
}

void Client::update() {
     // here I need an access to the `clients` map. What I should do now?
}
Hi there? Any tips how to solve the problem above? I'm facing it for a few days.
I just wonder should I use std::async or not?
 
you need to lock on clients_mutex in update
 
@ratchetfreak It's locked already.
Or should I just check which thread owns the lock?
 
lolno
well, either you assume that update operates on a locked context, or it doesn't
there's also a third option of introducing a std::recursive_mutex
note that all of these suggest you have a tight coupling
why does Client need to operate on a clients map directly
 
@milleniumbug Client updates Player class. Sometimes it needs to reply [to a user] with a message and sometimes not.
Client is a helper for server's client.
 
Client is a connection to a client?
 
2:14 PM
@ratchetfreak Exactly.
@milleniumbug So the best solution is to use std::recursive_mutex?
 
ok last enough question about that kind of crap? I understand that
int (*ap)[2]
is a pointer to an array with 2 elements just to understand how things work, how would I take this expression to "craft" a array of these kind of pointers?
This does not work:
int a[] = {1,2};
int (*ap)[2][2];
ap[0] = &a;
 
@SzymonMarczak it would solve this problem, probably won't solve other problems if you have them, but I'm not sure if I care at this point
 
@milleniumbug Also I have another function.
void GameServer::read(std::function<void(std::map<WebSocket<1> *, Client*> *)> func) {
    std::lock_guard<std::mutex> guard(clients_mutex);
    func(&clients);
}
 
@milleniumbug thanks
 
So I would do:
    server->read([&](std::map<uWS::WebSocket<uWS::SERVER>*, Client*> *map) {
        // some operations here...
    });
but the mutex is locked already
 
2:23 PM
sounds like you are locking the map too often TBH
I mean that the single lock over all clients is too coarse and will effectively make your code singlethreaded
 
@ratchetfreak That's true. My application is two-threaded.
 
one thread too many, I'd say
 
@milleniumbug I can't. The lib github.com/uNetworking/uWebSockets is async...
 
struct obj
{
	char name[20];
	int age;
	std::string addr;

};



int main(int argc, char* argv[])
{
	obj person {char(argv[1]), atoi(argv[2]), char(argv[3]) };
	std::cout << person.age << " " << person.name << " " << person.addr << std::endl;
    return 0;
}
i have an error
in the cout
no operator "<<" matches these operands
it give me the error in the << before person.addr
why?
what am i doing wrong?
 
use std::to_string maybe?
 
2:29 PM
ok ill try that
 
lol the multithreaded_echo.cpp example in that lib is hilarious
 
namespace std has no member "to_string"
^ error
 
someone doesn't know you can default construct std::threads
and you can move assign temporary ones
 
nwp
@jeyejow That is not what I get.
 
2:35 PM
@jeyejow add #include <string> to the includes
 
ok, ill do that :o
it worked ehehe
ty
 
also jey go to tools->options->Text Editor->C++ and turn on line numbers
 
@Froglegs oh nice, thanks!
well i got a weird output from that code
^
i use the paramaters: je 12 street
i got weird alien text
why
 
@milleniumbug Or maybe this way stackoverflow.com/questions/28825749/…? I just need to make sure the mutex is locked by current thread, then I can go ahead (I think?)
 
@jeyejow because char(argv[1]) doesn't do what you think it does
@SzymonMarczak or make everything run in a single thread
 
2:41 PM
how do i convert it to a char so i can store it then? @ratchetfreak
or what should i do
should i put in the struct char* name
?
 
nwp
@jeyejow I recommend you add QMAKE_CXXFLAGS += -Wall -Werror to your .pro file. Assuming you are not using the VS compiler.
 
@ratchetfreak I can't because github.com/uNetworking/uWebSockets is 100% async.
and it isn't non-blocking
 
@nwp im using visual studio 2017
 
@SzymonMarczak all handler code is don't inside the run call which will block until you shut it down.
 
jey the code you posted does not compile so you would need to tell us what changes you made
 
2:43 PM
@Froglegs ok, ill post
#include <iostream>
#include <string>

struct obj
{
	char name[20];
	int age;
	std::string addr;

};
int main(int argc, char* argv[])
{
	obj person {char(argv[1]), atoi(argv[2]), char(argv[3]) };
	std::cout << person.age << " " << person.name << " " << person.addr << std::endl;
    return 0;
}
 
do you not get any warnings?
 
:v probably, but i dont know how to see the warnings in vs
 
@ratchetfreak The uWS server is always up.
And my game world is in the 2nd thread.
 
right click on the project, click properties, under configuration properties, go to C++->general
turn warning level to 4, and set Warnings as errors to Yes
 
nwp
@jeyejow try QMAKE_CXXFLAGS += /W3 /WX
@Froglegs That is for visual studio, not for Qt Creator.
 
2:46 PM
those instructions are for visual studio
 
ok, i did that, this is the build output
1>------ Build started: Project: structs_learning, Configuration: Debug Win32 ------
1>structs_learning.cpp
1>c:\users\julio\desktop\structs_learning\structs_learning\structs_learning.cpp(20): warning C4302: '<function-style-cast>': truncation from 'char *' to 'char'
1>c:\users\julio\desktop\structs_learning\structs_learning\structs_learning.cpp(20): warning C4838: conversion from 'int' to 'char' requires a narrowing conversion
1>c:\users\julio\desktop\structs_learning\structs_learning\structs_learning.cpp(20): warning C4244: 'initializing': conversion from 'int' to 'char', possible loss of
i dont think there are warings there
oh
nevermind, i opened my eyes
 
you did not turn warnings to errors on it looks like
yes lots of problems;0
 
then i guess my other project also has alot of warnings ahahah :p
how do i fix these warings?
truncation from char to char*
what is that
 
other way around
you are converting a pointer into a char--
 
the char(argv[1]) remember that argv[1] is a char*
 
nwp
2:49 PM
@jeyejow Search for for example "warning C4302", then look at the explanation they give you, then look at your code (you should be able to click on the issues to go to the line) and you should be able to figure out why it complained and how to fix it.
 
so i need to do this &*char argv[1] ?
i eard the & and * anulate each other
 
nwp
maybe you should consider reading a book
 
they are so expencive :C
 
change your name member to either a std::string or a const char*
and get rid of the conversion to char
 
don't suggest using const char* ever
 
2:53 PM
is const char * bad?
 
its the C way
 
are there online courses of C++ or books for free? i have an android app and i usually learn from there
 
@jeyejow There are lots of them--unfortunately, at least of those I've looked at, the quality ranges from bad to much, much worse.
 
you should use std::string since using const char* requires understanding scope/ownership, and you would likely end up writing very broken code
 
#include <iostream>
#include <string>

struct obj
{
	std::string name;
	int age;
	std::string addr;

};
int main(int argc, char* argv[])
{
	obj person {argv[1], atoi(argv[2]), argv[3] };
	std::cout << person.age << " " << person.name << " " << person.addr << std::endl;
    return 0;
}
 
2:59 PM
@Froglegs i did and it gave me no error, then i run the program and it outputed the memory address on the variables :V
 
probably because you left the char(argv[1]) in
idk
 
@ratchetfreak your code gives me error in atoi
this is the code i currently have
#include <iostream>
#include <string>

struct obj
{
	std::string name[20];
	int age;
	std::string addr;

};



int main(int argc, char* argv[])
{
	obj person {argv[1], atoi(argv[2]), argv[3] };
	std::cout << person.age << " " << person.name << " " << person.addr << std::endl;
    return 0;
}
it gives me an error in atoi()
 
0-o
you have an array of std::strings jew
jey sorry
 
lmao
omg
im so dumb
 
@ratchetfreak please no atoi
std::stoi maybe
 
3:02 PM
is atoi bad? i use it alot
to convert numbers that come in the arguments
ok it works now the code
 
@milleniumbug std::recursive_mutex is awesome! It rocks!
 
@SzymonMarczak recursive_mutex often indicates that you have no idea what you are doing
please, if you don't have a clue why you need it, don't use it
 
@login_not_failed Why?
 
personal experience
 
I don't wanna pass unique_lock through all function to check if the mutex is locked by current thread or not.
 
3:09 PM
see, you have some underlying archetectural problems, that you want to solve with a silver bullet
 
@jeyejow It's fairly poor. It's ambiguous. When it returns 0, you have to determine on your own whether it's indicating an error, or the input actually contained 0.
 
or have 2 versions of functions, one where you can assume the mutex is lock and one where it isn't locked
@JerryCoffin a hallmark of most early C apis
 
@JerryCoffin what do you recomend for me to use insted of atoi????
 
@jeyejow @milleniumbug already mentioned std::stoi. If you insist on fiddling with C-style strings, see strtol and company.
 
would this work?
#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
	std::string::size_type sz;
	int number = std::stoi(argv[1], &sz);
	std::cout << number << std::endl;
	return 0;
}
i think not
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
Error launching program (Aborted)
 
3:22 PM
@jeyejow Anytime you use argv, you want to start by checking argc to ensure that the argument you're trying to use actually exists.
 
@JerryCoffini know :p this is just a test
and now the code works, i have no idea why
 
Second, stoi signals errors by throwing an exception. If you want to recover from such an error, you have to do so by catching the exception.
 
how do i know witch exception was trowned? with the GetLastError?
 
@jeyejow Normally, you'd read the docs, which tell you what exceptions it can throw. Then you specify the type of exception you're going to catch. e.g., try {..} catch(std::exception const &e) {/* handle exception here */}.
 
3:25 PM
then the code inside the catch is only executed when an exception was thrown inside the try block
 
GetLastError is a Windows thing that's (almost) entirely orthogonal to exceptions.
 
hi. what sense of using POLLHUP with sockets.?
 
@login_not_failed So how would you solve it? My application is two-threaded. The second thread is a game world. If it needs an access to clients map it calls GameServer::read. The first thread is a WebSocket server. It's blocking and it's asynchronous. Client class can't access the clients map directly. It has to call GameServer::read too.
h.onMessage([&](uWS::WebSocket<uWS::SERVER> *ws, char *message, size_t length, uWS::OpCode opCode) {
	if (opCode != uWS::BINARY) {
	    return ws->close();
	}

	std::unique_lock<std::mutex> lock(clients_mutex);
	if (clients[ws]->handleMessage(ByteBuffer(message, length, true))) { // returns true if there's need to disconnect
	    lock.unlock();
	    ws->close();
	}
});

h.onDisconnection([&](uWS::WebSocket<uWS::SERVER> *ws, int code, char *message, size_t length) {
	std::unique_lock<std::mutex> lock(clients_mutex);
Scenario:
Thread 1 recieves a message, it calls `Client::handleMessage` (and `handleMessage` calls Player's function. what function? it depends on the message). Sometimes Player wants an access to the `clients` map (it would call GameServer::read), but it can't lock std::mutex because it's already locked. What's the solution?
I think I've explained here everything.
 
@SzymonMarczak yea, i'm a bit overwhelmed with my current work too, so this comes as a wall of unreadable text, lol sorry
 
@GreenTree It tells you that the remote has closed its end of the socket, so once you read all the outstanding data, you might as well close your end and remove it from the set you're polling.
 
3:29 PM
@SzymonMarczak AFAIU, you want some sort of message system, analogous to pipes in unix, right? (read the whole thing diagonally, sorry, but I'm at least honest here)
 
ok, important question actually, how to i make sure the user doesnt input a ridiculouly big number and crash my program?
 
nwp
@jeyejow by using a sensible function to read the number that handles ridiculously big numbers correctly
 
@login_not_failed IDK, I'm using github.com/uNetworking/uWebSockets for the WebSocket server. All I need to do is to handle the mutexes properly.
 
if you use stoi then catch std::out_of_range
 
@ratchetfreak ill try that, thanks!
 
3:33 PM
well, that's the problem. when peer gets closed, server socket is getting POLLIN ( then i'm checking read == 0 to detect remote has been closed ).
 
@ratchetfreak and @nwp can you read this small wall of text above? I'm facing that issue for 2 days and I can't solve it... I can't make my app single threaded cuz uWS is blocking.
 
@ratchetfreak does the std::out_of_range works for other things then stoi?
 
@jeyejow look at the docs of the things you are calling
 
@ratchetfreak oke
ty
 
nwp
@SzymonMarczak "It's blocking and it's asynchronous." doesn't make sense to me. It should either be blocking or asynchronous, not both.
 
3:40 PM
@nwp github.com/uNetworking/uWebSockets If I call hub.run() it blocks the thread. And the quote for asynchronous: "It features an easy-to-use, fully async object-oriented interface and scales to millions of connections using only a fraction of memory compared to the competition."
 
it's yet another async lib that takes control of the main loop...
 
@ratchetfreak Exactly!
 
drop it for a lib that lets you poll a few network events at a time and do your own processing inbetween
 
4:16 PM
@ratchetfreak @login_not_failed this is what I was looking for: stackoverflow.com/questions/21892934/… thanks for help! I really forgot about defer_lock
 
4:59 PM
@SzymonMarczak I shamelessly did absolutely nothing
 
@login_not_failed You said to avoid recursive mutex :P That's good tip.
Also, what does shared mutex stands for?
 
@SzymonMarczak oh yes, I forgot lol
@SzymonMarczak all «shared» things in C++ relates to the ownership of the object (tried to explain it in a broad way)
 
> In contrast to other mutex types which facilitate exclusive access, a shared_mutex has two levels of access: shared - several threads can share ownership of the same mutex. exclusive - only one thread can own the mutex.
 
lol I got error: ‘shared_mutex’ in namespace ‘std’ does not name a type
I did #include <shared_mutex>
 
oh wait (since C++17)
 
5:09 PM
thanks :P
 
13
Q: Why shared_timed_mutex is defined in c++14, but shared_mutex in c++17?

peku33C++11 introduced std::mutex and its extended version - std::timed_mutex. However, in c++14 we have std::shared_timed_mutex, but its 'parent', the std::shared_mutex is going to be added in c++17. Is there any reasonable explanation for that? If I'm not going to use 'timed' functionality of std:...

 
i have a question not really c++ related, just wondering if annyone knows, i tried making my own file extention (for example: file.hhh), and i want all files that end in .hhh have a icon, and not just that default whit thing windows puts, how do i do that? how do i tell windows that files with the extention .hhh have a certain icon that ill provide?
 
5:41 PM
@jeyejow It's stored in the registry.
 
@JerryCoffin thanks! ill do some search to see if i can find / change in the registry
 
@JerryCoffin thanks alot! :D this ill add value to my project i hope!!
 
6:23 PM
is there annyway of "locking" a file? for example, sometimes if we try to delete a file that is being used by annother program, the Windows doesnt let us it says we must first close the program that is using the file before deleting the file. I wanna do that in my program, since i am scared that the user could delet the file that im writing stuff to, how can i make in c++ something that locks the file while i am writing to it? does the OS alreaddy does that when i am writing to the file?
im using the WriteFile() function, msdn.microsoft.com/en-us/library/windows/desktop/…
 
nwp
@jeyejow Windows blocks files from getting deleted while open. Linux doesn't.
@jeyejow You shouldn't
 
@nwp why not?
cause it takes user control?
 
nwp
6:39 PM
follow the arrows, that was directed at using WriteFile, not at blocking the file
 
i shouldn use writefile? why? what should i use then?
 
nwp
std::ofstream
 
and why should i use that over writefile() ?
writefile writes in bytes
 
nwp
because it is from an international standard and will be relevant at all times while WriteFile is from an old C interface
 
does it write in bytes to a file?
 
nwp
6:42 PM
it can if you want it to
 
can i read from a file with that?
and does it retun the things read in bytes?
can i write to a file in the X position in bytes?
 
nwp
@jeyejow that would be std::ifstream
@jeyejow it can if you want it to
@jeyejow yes
 
wow, i never eard of that and i can do with it the same i can with the writefile(), readfile() and setfilepointer()
:O
do you have something like that also for devices?
 
nwp
You can try to give it a path that specifies a device and hope it works. Otherwise no.
 
ok, ill try to do that, ill search for examples to see how it works
fck i need to "purchase visual studio"
do you know anny good c++ compiler that works in windows?
that i can compile and generate an .exe with my program?
and free
 
nwp
6:53 PM
@jeyejow you don't, there is a community edition that is free to use
 
well i think i installed the wrong one then, it says i must activate the key to use the product
awsdawsdwas
y u do this microsoft
i cry everytime
 
nwp
otherwise I would recommend Qt Creator because it comes with an installer that installs gcc in the correct version and paths so you don't need to mess with paths
 
i tried installing QT once, it gave me an error everytime at 40 something %
i have sublime text but i cant really compile there / generate a .exe with my c++ code
or at least i dont know how to
 
03:00 - 19:0019:00 - 00:00

« first day (353 days earlier)      last day (2491 days later) »