« first day (3520 days earlier)      last day (1421 days later) » 

1:36 AM
Ugh... Why is shared_ptr such a mess and why does it fail on an allocator that should technically work: coliru.stacked-crooked.com/a/f7580be2aa20c456
 
 
1 hour later…
2:53 AM
should it be std::make_shared?
 
allocate_shared is a feature that allows you to pass in an allocator for the shared_ptr to use to allocate its memory
std::make_shared in libstc++ v3 is a forwarding call to allocate_shared
note that there is no std::allocate_unique because it's fairly easy to implement meanwhile since shared_ptrs are such complicated beasts the std committee probably thought it fit to give us the impl for now
 
Unlike the std::shared_ptr constructors, std::allocate_shared does not accept a separate custom deleter: the supplied allocator is used for destruction of the control block and the T object, and for deallocation of their shared memory block.
also does the allocator go in the template?
 
the allocator is inferred
you can, but it's unnecessary
this whole rebind metafunction shenanigan needs to end
 
Hmm, well this dude seems to have a working example: stackoverflow.com/a/22487540/314290
 
Yeah but that is the bare minimum definition of an allocator - mine is a tiny bit more complicated but I guess that broke a lot of things
 
3:06 AM
The real solution is to avoid inheritting from std::
I mean, I wrote a shared pointer allocator today and didn't shoot myself in the foot :-)
 
that's true - but I was actually writing a test for a project of mine with allocators and I wanted to see if it would work for any allocators other than std::allocator<T> :-)
I think you're just much smarter and meticulous than me then
 
Well I've been personally battling a lot with fragmentation today, trying to figure out a good strategy for dealing with GPU allocation errors.
I might have to bite the bullet and areana allocate at the process level and chop off chunks with a custom allocator.
Somehow this strategy means that the underlying allocator (like malloc, or cudaMalloc) is fucked. (Because the underlying allocator should maintain a healthy arena...)
 
I see - actually my pet project deals with something really similar - may I ask you a few questions?
What's the biggest problem with fragmentation in your use case? is it inability to allocate large blocks with limited memory? speed?
 
Its not speed. So an allactor that stalls until it succeeds would be good. That is actually what I've been experimenting with.
 
What kind of tools do you use to quantify the fragmentation in your program or is it just a hunch?
@Mikhail so it's actually just so much frag that you can't even allocate large blocks anymore?
would that usually be a std::terminate call
 
3:16 AM
So, total memory is around 8 GB, and maybe 2 GB are free. But sometimes calls to the allocator start failing for ~40 megabyte blocks. The allocation failures are for GPU memory. The error code raised are related to cudaMalloc and are spurious.
Where it makes me sad is that sometimes the fragmentation happens when starting a new process. For example, old process had a bunch of memory allocated. Then launch new process and get spurious allocation failure. Look at memory free (which supposedly per process ) and see like 90% free.
But the recovery solution that seems to be working is just wait for a second, and then retry...
I don't recall experiencing memory fragmentation problems on Windows. And actually got in a bunch of trouble when moving python across platforms (when the interpreter started crashing).
 
A base class `A` and derived class `B` are implemented as such:

```
class A; class B;
class A { private: int value; public:
constexpr inline A(int const value) : value{value} {}
constexpr inline A(A const& a) : value{a.value} {}
constexpr inline A(B const&);
};
class B : public A {
private: enum {off, on} whatever;
public: constexpr inline B(int const value) : A(value), whatever{on} {}
};
```

with class `A` specifying a multiple constructors including one that accepts a class `B` object.
I want the constructor that accepts the derived class (i.e.: `A(B const&)`) to explicitly call another
 
3:36 AM
@Mikhail this is super interesting - thank you for this!
I'm actually making a tool that visualizes the fragmentation from processes
40 MB allocation fails is pretty surprising. I'm guessing there are a lot of processes going on?
 
Maybe, but I think the underlying issue is that memory allocators for the GPU are less developed. At one point the devices didn't have hardware memory protection, etc.
Visualizing memory allocator pressure between processes seems to be getting into the OS's job. Although for Linux there may be some direct ways to assay it.
If I recall gitlab was the butt of a lot of jokes for restarting their server every few minutes due to memory allocation failure :-)
They called it unicorn-worker-killer or something, although we all know the real unicorn killer was gunicorn
One other thing that stands out in the log snippet above, taken from Gitlab.com, is that 'worker 4' was serving requests for only 23 seconds. This is a normal value for our current GitLab.com setup and traffic.
and other amusing fragments.
 
4:02 AM
...
 
4:13 AM
@Mikhail I'm actually not too familiar with cudaMalloc - is there a C++11+ allocator that can do this for you?
And yes memory allocator pressure between processes isn't something I'm making :/ unfortunately it'll have to be within a single C++ program.
(but if you observe memory frag in the beginning of a process, then it's indicative of other processes causing it to choke I guess)
 
 
2 hours later…
5:53 AM
What's so special about WinMain@16, anyways?
Also, there any chat rooms on StackOverflow for Assembly (any variation i.e.: FASM, GAS, NASM e.t.c.)?
 
WinMain is just the default entry-point that some win32 linkers use
 
FASM had a nice webboard
 
AAB
6:58 AM
Hi all,
I am writing a simple c++ binary to detele files
I have tow rite in C++ 11
so far using struct *dirent seems like the way to parse
Should I display to the user the number of files found for delete or just delete the files and return if the operation succeeded or failed?
the number of files can be very large
 
I don't think there's a right or wrong, depends on what you want to do.

also dirent sounds more like C than C++11 :P ,
 
AAB
@PeterT yes dirent is C
 
Just use C++17 and std::filesystem
or boost::filesystem
 
AAB
@Mikhail boost was my option to but I have been asked to not use boost
and I have to do it C++ 11
so using dirent C seemed like an easy way
I am actually concerned about how I should make it for end user
As in should I ask the user for confirmation before delete and display the number of files found or go ahead with the process.
 
steal the man page from rm
In computing, rm (short for remove) is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell. == Overview == The rm command removes references to objects from the filesystem using the unlink system call, where those objects might have had multiple references (for example, a file with two different names), and the obje...
 
AAB
7:09 AM
:P
Guess will have to do something similar or ask if it fine to go this way..
asking user confirmation and displaying file count seems like a bad idea especially if file count can be high
:P
thanks @Mikhail @PeterT
 
 
9 hours later…
4:40 PM
 
 
2 hours later…
7:10 PM
 
 
2 hours later…
8:51 PM
What do you guys think of this guideline?
So, in my case I have a lot of struct A{bool is_valid();} and struct AA: A {bool is_valid();} which would all need to become virtual for some reason to meet this guideline.
 
Are you not marking them virtual because you're afraid of the overhead of vtable lookup?
I think the guideline makes sense for a large scale project where code readability becomes more important
 
Yes, that is one of the reasons.
But I don't also see how it improves readability.
I mean, you can verify that your function names match with override...
But in my case the "is_valid()" isnt' a contract.
Also some cases include an "approximately_equals" which is only implemented by classes that have floating point members.
Its basically saying all overrides should be virtual.
 
9:24 PM
Also static analysis tools seem to be lighting up a lot of false positives related to noexcept. When you mark a function that throws as noexcept these tools claim this is an error. But the intention was to call std::terminate because the code won't handle that error.
 
10:10 PM
If I'm not mistaken one of the things it's saying about "all overrides should be virtual" is the fact that it's masking the base class's function if not marked virtual. If you're not using virtual in this case why not just use SFINAE and check for existence of is_valid() in structs that don't inherit from each other rather than using inheritance and hiding the base class function?
 
Well, in my case I don't care if some structures don't implement the is_valid() check, and this is especially true of the approximately_equals() check. Somehow the argument that all overriding must be virtual is kinda wacky.
 
10:26 PM
Ah.. it sounds like a very complex scenario and probably has something to do with the design. I don't have enough context to really play devils advocate in this case but I think in general the style guide shouldn't be applied universally
sometimes you have no choice :/
 
That is a very political answer :-)
 
10:40 PM
Making sweeping judgements is not my forte
 
Another one that keeps pissing me off is this: docs.microsoft.com/en-us/cpp/code-quality/c26447?view=vs-2019
A big part of why its a problem is that its impossible to use dynamic memory and have your stuff marked as noexcept.
 
Hello, can someone help me about a very short question. İt is very important
int add (int i)
{
return i + d;
}

void p ()
{
const int d = 1;
print(add(20)); // (1)
}

void q ()
{
const int d = 2;
print(add(20)); // (2)
}
a) If the language is dynamically scoped, what would be printed at points (1) and (2)?
b) If the language is statically scoped, what would happen?
 
10:56 PM
@Coder123 we're not here to do your programming languages theory course homework
 
this is not my homework. I am trying to understand static and dynamic scoping. I found it from google. İf you want I can send link
 
btw, this doesn't even work for statically scoped languages
Because you don't have a top level definition for d in this scope
 
I think there are ample resources online for static/dynamic scoping. How does us giving you the answer help?
 
Okey, thank you
 
11:02 PM
Also we need a Qt version of this : smore.com/clippy-js
I wonder how much trouble I'll get into if I include this in commercial software :-)
Does MS have a patent on digital assistants or something?
Would be fun to include on an endoscope I worked on; "Looks like you're trying to perform a colonoscopy!".
 
oh god I'm stuck in a chicken-or-the-egg problem
If I decide to hack GCC's allocator implementation and make it do fancy things, I'm not allowed to use stl containers (because they use the allocator implementation) in the implementation of the allocator
So therefore I have to roll my own stack, map and vector...
 
Can you instead make the changes in libc?
 
well actually that's what I mean - libstdc++-v3
out of the entire toolchain for gcc, the only part I'm changing is the allocator implementation and there's no way to move allocators out of the dependencies of the stl containers that I'd be using
 
Doesn't libstdc++ call some C library shim before hitting the actual linux system allocator? (I might be wrong)
 
@Mikhail you must be thinking of the actual implementations of malloc(jemalloc/tcmalloc), new, etc
 
11:17 PM
Yeah
 
I mean the std::allocator which dispatches either of those two or others (i.e. on-stack arena memory for example)
i.e. it's a level higher than new, malloc, etc
 
I know that. But I think the implementation of new calls some shim that then calls the system allocator.
 
yes but that's not the level I'm dealing with. I'm providing an alternative implementation of std::allocator which is the source of the chicken-or-the-egg problem
FWIW IIRC new in gcc is by default jemalloc
 
Yeah, I know. But maybe you shouldn't have the "chicken-or-egg" problem by for example, avoiding it and working on the right level of abstraction?
Or just fuck it and write your own containers :-)
or maybe use boost :-)
 
@Mikhail unfortunately I want to capture more than just new use cases. Imagine someone wrote a cudaMallocator (that you might want to use in particular), and they don't call new and just calls cudaMalloc in the allocate(size_t n, size_t align) function for the allocator API. What happens then? I'd be leaking allocation information. In fact, I'd say most people using custom allocators are the ones who might find some use with my custom allocator code :-)
So... unless I'm missing something, this is the right level of abstraction, it's just the most PITA level as well
 
11:23 PM
Yeah, depends on what you're trying to do.
But writing your own allocator that doesn't rely on the std is pretty easy
 
@Mikhail that's a carrot or a stick situation. I don't think many people would opt in when I bash them w/ a stick and say "use my containers or else"
but that is in fact what I did here: github.com/OneRaynyDay/Erata so far.
yes. I'm gonna have to just reimplement a few containers and we can probably avoid this issue
 
Or just write an allocator
 
- by making a pseudo-inferior chicken to lay the eggs so the eggs can hatch the standard library chicken
 
there might be some misunderstanding here
 
11:27 PM
Sorry the other one was duplciated
I mean, just write an allocate that relies on the near native OS calls.
Like the thing I showed you for page locked memory
 

« first day (3520 days earlier)      last day (1421 days later) »