« first day (700 days earlier)      last day (2153 days later) » 
09:00 - 22:0022:00 - 00:00

9:49 AM
Hi
what's the C++ equivalent of this call
(C/C++)
fid = fopen([fpath, '/file.bin'],'rb');
content = fread(fid, 11,'single');
Trying to read through this: cplusplus.com/reference/cstdio/fread
but I get quite confused
 
10:05 AM
this is my attempt:
FILE* f = fopen(filename.c_str(),"rb");
char *content = (char*) malloc (sizeof(float)*11);
size_t result;
result = fread(content,4,11,f);
but it doesn't seem to work
 
Sam
10:42 AM
How do i correctly iterate over a vector of class objects and delete them? To avoid leakage
 
10:55 AM
@user8469759 use en.cppreference.com/w instead of that site
 
but still can't spot where the problem is
is there a way to check quickly if the file has been found?
 
11:13 AM
@user8469759 a) don't use C style IO b) just check if the iostream is truthy
eg. ifstream stream("filename");
if (!stream){ return; }
 
11:55 AM
 
Sam
@VioAriton thanks mate
 
Ron
12:22 PM
Can I survive without knowing too much about rvalue references?
Why would I want to extend the lifetime of a temporary?
 
@Ron Yes, the main reason to know about them is so you can enable move or if you have a class that is otherwise immutable to provide mutability for efficiency in some cases
 
Ron
Thanks, appreciate that.
 
@Ron lets say that operations on bar create lots of little bars you can rvalue qualify a mutation methods e.g. bar& doFoo() && so that doFoo() acts differently with an rvalue (modifies the temporary) so you can be more efficient.
That said, I've never actually seen this in practice because nobody has found a reason using a profiler yet to do it.
 
Ron
I see.
 
Other reasons to know about rvalues is to ban them for example. as const bar & will bind to a temporary which may be bad if you're returning references to the interior of bar (see std::regex) so you can delete a method taking an rvalue to prevent people from passing you temporaries
 
Ron
12:35 PM
In that case must I know the entire rvalue, lvalue list by heart?
 
@Ron nope, you can just delete like you would otherwise example see how it bans anything temporary strings in the last overload?
 
nwp
@Ron When you do const auto &connection = get_connection(); you don't want to have to care if get_connection returns a value or a reference.
 
Ron
Ah I see now.
All clear now. Thanks.
Can I skip the alignment part for now? Is alignment implementation dependent or standard defined?
 
@Ron mostly implementation
 
12:55 PM
QObject::connect(&timer, &QTimer::timeout, [&multiplier]() { ++multiplier; });
compiler noticed me that multiplier isnt a variable...
can not explain that to me
 
nwp
If it is a global variable you don't need to capture it.
 
its an private member....of the class in which ctor i call this connect function
when i do this, its o.k. ->>> [&]() { ++multiplier; }
 
nwp
Then it is probably capturing the this pointer and [this]() { ++multiplier; } should compile.
Alternatively you can probably do [&multiplier = this->multiplier]() { ++multiplier; }.
 
Is there a way to operate the screen shot buffer in memory?
I have a lot of code related to screenshots on the internet, but I have not found the code I really need.
Please help me get some minutes.
 
1:20 PM
@nwp thx nwp but why that doesnt work....is it because multiplier isnt declared in the scope of the lambda ?
 
nwp
@FerencRozsa You should have learned by now that "doesn't work" is not helpful. What is the error message? And since the obvious attempts failed, where is the code on coliru to show the issue?
 
Hi everyone!
How can I get answer in this chat room?
 
@nwp coliru.stacked-crooked.com/a/d5c8c2a1a7f0aff8 ->>Error is multiplier isnt a variable
 
float voxel_grid_dim_xf = (float) voxel_grid_dim_x;
	float voxel_grid_dim_yf = (float) voxel_grid_dim_y;
	float voxel_grid_dim_zf = (float) voxel_grid_dim_z;
	float num_chunks_xf = (float) num_chunks_per_dim[0];
	float num_chunks_yf = (float) num_chunks_per_dim[1];
	float num_chunks_zf = (float) num_chunks_per_dim[2];
	outFile.write((char*) &voxel_grid_dim_xf, sizeof(float));
	outFile.write((char*) &voxel_grid_dim_yf, sizeof(float));
	outFile.write((char*) &voxel_grid_dim_zf, sizeof(float));
	outFile.write((char*) &voxel_grid_origin_x, sizeof(float));
isn't from the std::ifstream correct for reading what I've been writing in the lines above?
at least the first line
 
nwp
@Kaizen You did pretty much everything right. A clear question and example code. Unfortunately it looks like none of the people here right now can help you. Either be patient or try elsewhere.
 
1:30 PM
@user8469759 Note... using C style casts is usually a bad thing as it may not do what you expect
 
@nwp Thank you.
 
@user8469759 if writing out use a std::ofstream
 
ok, but I'm sure the writing is correct
 
the i stands for input
 
I've just added the other lines (std::ifstream) to read what I've just written
 
1:31 PM
@nwp, I am here for the first time. Can you teach me?
@nwp Am I disturbing you?
 
nwp
I got to go do something else for a bit. Again, be patient or try elsewhere.
 
@Mgetz replacing the writing with outFile << ....
easier to read and hopefully nothing will be screwed up
 
@user8469759 that will write text not binary
if that's what you want
 
shouldn't write it binary if I open the ofstream with the appropriates flags?
I want binary
 
@user8469759 the binary flag only says to not mess with text encoding output. If you want to write or read binary you need to use write and read
 
1:43 PM
so the write was correct then
for this purpose
 
@user8469759 Yes, you might have byte order issues depending on architecture
 
how do I read binary then?
I'm opening the ifstream
with the ios::in and ios::binary
 
insofar as you're only using it on one type of stream, you're fine with read
e.g. if you use write to output you should probably use read to input
 
basic_istream& read( char_type* s, std::streamsize count );
but just for the first 11 floats
what would be the inputs?
 
@user8469759 inputs?
 
1:47 PM
for the read
 
a buffer and the size of the buffer
it's a byte buffer
 
so the buffer, in my case, should be like std::array<char,11*sizeof(float)> ...
and the count would be the 11*sizeof(float)
is it correct?
 
@user8469759 I'd try std::array<float, 11> first and then do a reinterpret_cast<char*>(inputs.data()) when passing it in. Don't forget to pass the right size though
 
which is 4*11
 
yo
if I do
if(std::shared_ptr == std::shared_ptr) does this compare the shared_ptr objects or the original objects they point to
or do I have to do
shared_ptr.get() == shared_ptr.get() ?
 
1:52 PM
sorry for the RTFM... but RTFM is the right answer in this case
 
Note that the comparison operators for shared_ptr simply compare pointer values; the actual objects pointed to are not compared
so
 
@Mgetz ok, it seems be doing something now
 
it compares pointers, not objects
 
lemme check if it correct
(thank you btw)
 
I have to use .get() to compare objects, nice thanks!
 
1:53 PM
@Dariusz no... you didn't read the documentation
see case 1
 
its what It says above
Compares two shared_ptr<T> objects or compares shared_ptr<T> with a null pointer.

Note that the comparison operators for shared_ptr simply compare pointer values; the actual objects pointed to are not compared. Having operator< defined for shared_ptr allows shared_ptrs to be used as keys in associative containers, like std::map and std::set.
it compares pointer values, not objects they point to
 
@Dariusz .get() won't solve that
you need to do *a == *b
 
son of a
 
doing .get() is equivalent to case 1
 
whhhh thanks! I though get was the answer, why do we even have the damn get... since I learned the *a I mostly use *a...
so .get() return pointer?
 
1:57 PM
@Dariusz yes, you use .get() to pass the value to a function that doesn't take ownership. Tbh I'm concerned you're using std::shared_ptr at all... it's a code smell because 99.99999999999999999999999999999999999999999% of the time std::unique_ptr is the correct way to go
 
hmm
 
What I suspect you're doing is passing smart pointers around
which is a massive anti-pattern
 
I don't understand how unique_ptr works. I know, only one object can hold it at a time.. but I dont get it. I have 3 classes, each have map with shared_ptr<> of objects that they share between eachother. I dunno how the unique_ptr handles that. if only 1 class has that object and rest null or what
its black magic
 
@Dariusz can't one of the objects be the true owner?
and the other two objects just interact through that object?
 
and the rest will be what, shared_ptrs?
so
I have 3 classes A ,B C, A is the unique_Ptr, and if B and C wants to do anything with object they have to ask A for it?
 
2:00 PM
@Dariusz yes...
 
nwp
@FerencRozsa Can you make an example that actually shows the error?
 
hmmm it feels painful....
 
2:18 PM
@Mgetz once I read the first 11 floats how can I keep reading?
like if I do the read again would it start from the beginning?
 
@user8469759 the same way? the index into the file has been incremented by sizeof(float)*11
 
2:31 PM
when I use shared_ptr and do *x= *c, what happens to old x object? Does it get auto deleted? Or do I need to somehow delete it before replacing it?
 
@Dariusz it's reference count gets decremented
and c's get incremented
 
wait
it does not replace *x object for all shared_ptr pointing to it?
 
@Dariusz no, why would it?
that's not how shared pointer works
 
say I have
shared_ptr x point to 0x0032523 object
shared_ptr y point to 0x0032523 object
shared_ptr z point to 0x0032523 object
now if I want to say do *x = *c points to 0x0111111 object, how can the y and z also change their point to *c?
esentially I want to replace object that all of my shared_ptr point to
 
@Dariusz you'd have to manually update them. This is why I suggested having one owner
 
2:42 PM
3
Q: Replace all references to a object in a shared_ptr<T>

TimIs it possible to replace the object where multiple instances of a shared_ptr refer to? Maybe I am not really clear, so I'll give an example: shared_ptr<Base> a = new Derived1(); auto b = a; auto c = b; // This function replaces the object where a, b, and c point to. magic(a, new Derived2()); ...

im ofically depressed.
hahahahahahahahahahah
 
@Dariusz why?
 
or you can change the object at 0x0032523 so it becomes the object at 0x0111111
 
Sam
Are there tools I can use to ensure I've done garbage cleanup on my application? I'm looking at the call stack but not really sure I understand whats going on
 
nwp
@Sam On linux there are valgrind and leak sanitizer. On windows get a linux VM.
 
Sam
I've also just read that I shouldn't make objects of my class like Class newObj = new Class
184
A: General guidelines to avoid memory leaks in C++

Ross SmithI thoroughly endorse all the advice about RAII and smart pointers, but I'd also like to add a slightly higher-level tip: the easiest memory to manage is the memory you never allocated. Unlike languages like C# and Java, where pretty much everything is a reference, in C++ you should put objects on...

whoops
 
nwp
2:51 PM
Yes, not using new makes avoiding memory issues a lot easier.
 
@Sam I'd start with RAII
 
nwp
@Sam Also that code most likely doesn't compile.
 
@Sam welcome to C++ it's not Java
 
Sam
But in all of my functions which reference classes I've been passing in pointers
My code does compile
 
@ratchetfreak how to do that?
 
nwp
2:53 PM
Then you probably forgot to type * in the example.
 
Sam
So, instead of using Subject subject = new Subject(param1) I'm going to use
 
nwp
@Sam 1. You don't need to, references exist. 2. You don't need new to make a pointer, & can do that too.
 
Sam
Subject subject(param1)
Subject* ptrSubject = &subject
 
is there a Java synchronized in C++?
or I have to lock it manually
 
nwp
@VioAriton folly::Synchronized basically does the same as Java's synchronized keyword.
 
3:00 PM
@Sam why? You don't need to do this
 
Sam
Because I've been accessing member functions of the class using subject->getSomething()
I can't use *subject->getSomething()
 
@Sam find and replace subject-> with subject.
 
Sam
Ahh OK. And what is the benefit of declaring objects this way? If you don't mind explaining
 
@Sam when you leave the scope the objects cease to exist, as do any of their child resources if you've written your object correctly
 
Sam
So do i need to worry about using delete &subject
 
3:04 PM
also under most circumstances they are allocated on the stack not the heap meaning that no dynamic allocation occurs
@Sam no, using new and delete is a code smell. If you're doing it you're probably doing something wrong
 
Sam
hmm ok
 
That's not to say dynamically allocated objects don't have a place... but std::make_unique is a much better way to do that
 
Sam
Can i use stack view on VS to see if the objects still exist at the end of my program run?
 
@Sam if you're using stack based resource management then that's irrelevant because the standard guarantees they will be destructed before that
 
Sam
OK. So I just hope? :P
 
3:06 PM
@Sam no hoping about it
if they aren't then the compiler is not compliant
 
Sam
OK. I'm slowly but learning
ish..
I declared objects in Java using new. I should have researched it a bit first.
 
@Sam well... I'd suggest getting the latest version of Bjarne's book
4253
Q: The Definitive C++ Book Guide and List

grepsedawkThis question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written...

 
Sam
ouchh
Reckon its readable on Kindle?
Sometimes (especially with Math books) the equations are somewhat hard to read.
 
@Sam see the second book he did... it's ebook only ;p
But I suspect the answer is yes... it's available on kindle
 
Sam
Look at those price differences :O
 
3:18 PM
does that book talk only about the basic stuff, such as functions, flow control, pointer etc?
 
@VioAriton it talks about how to code in C++ in an understandable educational way
 
Sam
Neat. I'm going to purchase it later on
Read it on my holiday.
 
yeah I got it too - didn't think C++ would be this difficult to learn. It's been 3 weeks and I still have no clue when to use pointers
 
Sam
I kind of understand pointers
In theory, not in practice
What language are you coming from?
 
java
 
3:29 PM
a pointer is an address to some data
 
Sam
We did a bit of Java in uni. Not much though
 
a pointer itself can also be data
 
yeah I know what a pointer is
I'm just not sure when to use them
 
Sam
When you want to point to data which can change value?
 
@VioAriton pointers are an advanced topic... and they do literally what the name implies, they point to something.
 
3:30 PM
I see people use pointers in their instance variables
 
@VioAriton not always a good idea
 
raw pointer when it doesn't own the value and the lifetime of the value will exceed the lifetime of the pointer
smart pointer when there is ownership (the lifetime of the object is tied to the lifetime of the pointer)
by value is most of the time unless you need allocation for some reason, like inheritance or dynamic array (use std::vector for that)
 
C++ is an ownership obsessed language because it's a resource oriented language. The goal being to access a resource and release it as soon as possible
 
yes but why would I point to something when I can just use
that something instead
 
because it's stored somewhere else or you don't know the size of the object at compile time
 
3:35 PM
@VioAriton a) you may need to share it around with only a single owner that manages lifetime. b) it might be optional (e.g. nullptr) c) it might need to have inheritance where you access it via the parent and don't know what the type will be until runtime
 
and you would store it somewhere else if you need it to survive returning from the function (and it's not the return value)
@Mgetz well for b) there is std::optional
 
@ratchetfreak not for parameters!
 
you cannot pass a std::optional to a function? that seems wierd
 
@ratchetfreak I think you can but I've been hesitant to do that because pointers are cheap and easy and preform the same function in that case
also I'm pretty sure you can't do an optional reference
> There are no optional references; a program is ill-formed if it instantiates an optional with a reference type. Alternatively, an optional of a std::reference_wrapper of type T may be used to hold a reference. In addition, a program is ill-formed if it instantiates an optional with the tag types std::nullopt_t or std::in_place_t.
 
isn't that about std::optional<T&>?
 
3:42 PM
@ratchetfreak correct, which is prohibited so if you want to make a reference parameter optional you'd have to go through a lot of hoops to get the same thing as T* = nullptr
I think that's clearly expressive of an optional non-owned parameter
 
@ratchetfreak That's not what I was looking for I was looking for T& so I'm not making a copy, that will copy
and create a temporary to boot
 
 
2 hours later…
5:22 PM
I'm getting CL_INVALID_WORK_GROUP_SIZE, but my local work size is 299 and my max supported WORK_GROUP_SIZE is 1024
is any of you familiar with this?
CL_INVALID_WORK_GROUP_SIZE if local_work_size is specified and number of work-items specified by global_work_size is not evenly divisable by size of work-group given by local_work_size or does not match the work-group size specified for kernel using the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier in program source.
in my case I have
size_t globalWorkSize[2] = { (mVoxelGridDim[1] - 1), (mVoxelGridDim[2]
				- 1) };
		size_t localWorkSize[2] = { (mVoxelGridDim[1] - 1), (mVoxelGridDim[2]
				- 1) };
		mErr = clEnqueueNDRangeKernel(mCmdQueue, mKernel[0], 2, nullptr,
				globalWorkSize, localWorkSize, 0, nullptr, nullptr);
where mVoxelGridDim[i] - 1 = 299 for i = 1,2
so it is evenly divisible
 
0
Q: Where is the C++ memory layout of objects documented?

Dun PealThis is a big question, so I'm asking for a reference rather than a booklet-sized response. I'm going through Stroustrup's Tour of C++, and it seems like the way objects are laid out is memory is fundamental to the design of many C++ features, e.g. PODs vs aggregates vs classes with virtual membe...

 
1 message moved from Lounge<C++>
 
0
Q: CL_INVALID_WORK_GROUP_SIZE opencl

user8469759I'm getting CL_INVALID_WORK_GROUP_SIZE, but my local work size is 299 and my max supported WORK_GROUP_SIZE is 1024. According to the documentation: CL_INVALID_WORK_GROUP_SIZE if local_work_size is specified and number of work-items specified by global_work_size is not evenly divisable by ...

 
5:48 PM
@DunPeal it's ABI specific
@user8469759 What's 299 *299?
 
how can i return boost streambuf from a function , should be very simple stackoverflow.com/questions/50798805/…
 
yeah I got the error
getting a worse one now
CL_MEM_OBJECT_ALLOCATION_FAILURE
 
@user8469759 reminder with OpenCL you need to detect quite a lot of these parameters based on target device
 
checking those indeed
 
Also remember that you probably want larger local workgroups that match your data sizes versus many global workgroups
 
6:05 PM
I just want this to run at least, I can think about optimization later
not sure what I can look up for the CL_MEM_OBJECT_ALLOCATION_FAILURE
 
6:20 PM
@user8469759 it's pretty clear what's happening... you can't allocate memory for that
that said... why are you using OpenCL?
Vulkan replaces it for this purpose
 
because I'm constrained to use that
is there a way to check why I can't allocate?
 
@user8469759 There is only ever one reason... you're asking for too much
or asking the wrong way
 
well I'm not getting any errors from the createBuffer's call
but I understood that's normal because such call doesn't allocate anything on the device
 
@user8469759 I can't say, I've done compute using DX12 not OpenCL
 
the only thing I can think of is that
from the host side
I'm creating a buffer for this
struct Cube {
	uint8_t id;
	int perm[NUM_VERTICES_CUBE];
	bool complement;
}
but on the kernel side I have something like
typedef struct {
	unsigned char id;
	int perm[8];
	bool complement;
} clCubeCaseEntry;
also on the C++ side there's some methods and constructor
not sure if this affects the size of the buffer
I think it shouldn't
this is what I have when I create the buffer:
size_t lutSize = NUM_CONFIGURATIONS * sizeof(Cube);
	mGpuLUT = clCreateBuffer(mContext, CL_MEM_READ_ONLY, lutSize, nullptr,
			nullptr);
	mErr = clEnqueueWriteBuffer(mCmdQueue, mGpuLUT, CL_TRUE, 0, lutSize,
			(void*) mLUT, 0, nullptr, nullptr);
 
 
1 hour later…
7:47 PM
almost every example I see, they name their parameters with m_name
what does m_ stand for
I mean instance variables
 
it's a type of hungarian notation
m stands for member
 
why is this "virtual void Notify(Notifier::NOTIFIED_EVENT_TYPE_T eventType, const void* eventData) = 0;" initialized with 0
since It's a function
 
it's a pure virtual function
without an implementation and making the class abstract
a derived class has to provide an implementation to be instanstiatable
 
8:17 PM
are void pointers used in C++?
I've bumped into one and apprently they are used in C
 
there are better alternatives
 
templates?
 
among other things
 
such as
 
8:40 PM
@VioAriton std::variant, std::any are in c++17 and are sometimes used for this purpose
they were also in tr1 boost previous to 17
Question: error: use of deleted function 'mynamespace::thread_guard::thread_guard(const mynamespace::thread_guard&)
 
looks like thread_guards are not meant to be copied
 
When I have a constructor thread_guard(std::thread&& _t) : t(std::move(_t)) {...} from mynamespace::thread_guard(std::move(some_thread));
Yes, I'm aware of that, but I std::move'd the rvalue into thread_guard right?
so I don't see how that was a copy per se
 
but what are you doing with that temporary?
 
nwp
@OneRaynyDay You moved the std::thread, but it's not complaining about that, it's complaining about thread_guard.
The compiler should show you the context in which you tried to copy a thread_guard.
 
guards are usually non-copyable and non-movable
 
8:52 PM
Ah. Duh, I was pushing them back into an std::vector, the guards. Obviously creates a copy there
Thank you; the error diagnosis message is like 3 pages long
and not a lot of context into vector except a single line for /bits/vector.tcc:97:40:
 
nwp
That is not the context you want though. You want the context with the push_back.
 
you should search until you find context in your code
that often points to where you went wrong (not always though...)
 
nwp
Looking at the first occurrence of "required from here" that is in your code tends to be useful.
 
so, in this situation there isn't an obvious line of code that is displayed from the compiler. It's not about the push_back either, I presume
I'll figure it out and report back
Ah, it's an extremely ugly error telling me that I'm not binding to a function pointer correctly. I'm guessing here is no implicit casting for the types
 
you can wrap it in a lambda who's signature is what the function expects and is just a call to the function you have
 
9:05 PM
Ah I see. Would you recommend the lambda or would you recommend std::ref()?
seems like lambda is not as necessary for this purpose
 
9:19 PM
Okay this is quite annoying:
vector<thread_guard> v;
for(...){
    thread t(...);
    thread_guard tg(std::move(t));
    v.push_back(std::move(tg));
}
The push_back is causing another copy ctor error. But I'm explicitly moving it
 
nwp
It shouldn't. But try v.emplace_back(std::move(t)); if you can.
 
and v.emplace_back(std::move(t));?
 
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/thread:126:5: error: declared here
     thread(const thread&) = delete;
     ^
still telling me that I can't copy it.
 
nwp
That is from a different context than you are showing though.
 
This is the context of within the stdlib
 
9:26 PM
you want the context in your code
 
I try not to post giant snippets(can't access pastebin at work). There is barely any context in my code, I can show you it though
This is the only thing:
 
try and recreate it on coliru.stacked-crooked.com
 
In file included from src/main.cpp:1:0:
src/xxx.h:17:7: note: 'mynamespace::thread_guard::thread_guard(const mynamespace::thread_guard&)' is implicitly deleted because the default definition would be ill-formed:
 class thread_guard{
Unfortunately I can't really go on the ideone type websites at work
I would've tried like 30 mins ago to give you guys an MVCE
 
nwp
Tell your admin/boss that their safety rules are impeding your work.
 
it's understandable; the environment that I'm working in values security very much
but yes, it is impeding my work :P I'm leaving this internship in a week anyways though
 
nwp
9:31 PM
"Security at the cost of usability comes at the cost of security"
@OneRaynyDay It should also tell you the context of where it wants to copy a thread_guard 1 line above that.
 
@nwp yes it does. It tells me it's in stl:
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/bits/stl_construct.h:75:7: error: use of deleted function 'mynamespace::thread_guard::thread_guard(const mynamespace::thread_guard&)'
     { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
 
nwp
Well, go up more until you end up in your own code again. The STL doesn't copy stuff by itself.
 
Ehm. Here's my full dump redacting some information. I hope you'd trust me that I have solely a single line of code that I wrote that the error complains about
ERROR: /src/BUILD:96:1: C++ compilation of rule '//src:main' failed (Exit 1)
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/memory:64:0,
                 from external/boost_1_67_0/include/boost/config/no_tr1/memory.hpp:21,
                 from external/boost_1_67_0/include/boost/get_pointer.hpp:14,
                 from external/boost_1_67_0/include/boost/proto/transform/default.hpp:21,
                 from external/boost_1_67_0/include/boost/phoenix/core/meta_grammar.hpp:17,
as I said before, only class thread_guard{ line was my code
 
what's on line 54 of main.cpp
also, what's the declaration of thread_guard
 
v.emplace_back(std::move(t))
and decl is a single move ctor and a dtor
no explicit, nada, single private member of std::thread
 
9:40 PM
add a move assign and delete the copy variants explicitly (rule of 5)
 
can you show the code
 
nwp
Ah, "add a move assign" is probably the key here.
 
give me one sec. I actually had the move assign commented out
Yes, compiled correctly. Thanks
I forgot to apply rule of 5 here; my stupidity. I even read about it in scott meyer's book
I'll also explicitly delete my ctor/copy ctors.
But honestly... How can you actually tell that that's the error from the dump above...?
like what the hell, C++
 
Hi guys! Cpp beginner here ... is there a possibility that a pointer I previously set to NULL changes to some random (and invalid) reference when the object gets copied, or because of something else?

The thing is I have a STL list containing objects, which themselves contain a pointer that points to NULL by default. I pass this list as parameter of a function (not as pointer though), and suddenly some of the objects in the list (within the scope of said function) have their pointers point to adresses other than NULL ...
 
C++ is not a memory safe language. Once you start corrupting memory, you'll see that variables which used to hold specific value may not hold it anymore
also: pointers
You're using containers, that's very good
but this sounds like you're managing memory yourself, given your description
 
9:48 PM
yes, I think so. My cpp skills are still quite ... rudimentary lol
 
are you on linux or your program can be easily run on linux
(because that would simplify debugging a lot)
 
I am on mac, but I think since both are unix, this should be the same?
 
no, though it actually helps the situation a bit
because it's likely you could easily run it on linux too
basically: Valgrind only runs on Linux because of how it works
 
It is a rather simple console application, so I don't think I am using anything fancy platform-specific
I also made sure not to use any system() commands, since they appear to be evil? :D
 
yeah
 
9:51 PM
or rather unsafe
 
nwp
Try passing -fsanitize=undefined,address to your compiler (which is probably apple-clang) and you should get better diagnosis of various issues including memory corruption.
 
yeah you could try sanitizers too
regarding manual memory management
Sep 15 '17 at 16:04, by milleniumbug
@StephanHofmann If you need to release anything, you're doing it wrong. (see: RAII)
 
I am very sorry if this is a dumb question ... but how do I do that? :D

I am currently using VS Code and debugging through that. However my debugging (and in general programming) skills arnt that good :D
 
every time you have a function that returns something, and you need to pass it to another function "when you're done", you're dealing with manual memory management
90% of the time I spend in this chat is to tell people to not do that
 
haha xD
I am very sorry
 
9:57 PM
that thing is a resource, and a resource has an owner. The owner is a class with a destructor and the rest of the "Big Five" that properly releases the resource
 
you can automate it by judicious use of smart pointer possibly with deleter
 
I don't even wanna know how my code looks to someone who has a bit more experience ... lol

Ugh ... Java was so much easier xD
At least I did not feel as dumb with java as I do right now with cpp
 
still, the best part is that you don't need to write that class yourself
 
nwp
@CrazyQwert I don't know, I don't have access to VS code right now. Try if it has something similar to this.
 
Java manages memory through GC, but it does nothing to help you manage database connections, native handles, files, GPU-allocated memory, and so on
 
09:00 - 22:0022:00 - 00:00

« first day (700 days earlier)      last day (2153 days later) »