d

How do i read a BufferedFile using read(ubyte[] buffer) when the buffer length is set at runtime?

自作多情 提交于 2019-12-10 13:30:47
问题 I have a binary file that is really a stack of files, the format is: lengh_of_subfile,subfile length_of_subfile is a 64-bit integer. I can read the long no problem but when I try to create a buffer for the subfile I get compile errors saying it cannot be read at compile time. What am I missing? I've written an identical extraction tool in erlang, PHP and C#... D is throwing me for a loop. void main(string args[]) { Stream file = new BufferedFile(args[1], FileMode.In); int counter = 0; while

Undefined symbol “start” while linking D program through LD

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 13:17:15
问题 I have following simple program: import std.stdio; int main(string[] argv) { writeln("Hello, world!"); return 0; } I'm building it as follows: DMD -c -m64 -od/proj/out -w -wi -fPIC -debug \ -g -I/proj/hello -unittest /proj/hello.d LD -L/usr/share/dmd/lib/ -arch x86_64 -execute -macosx_version_min 10.7 \ -pie -lm -lpthread -lphobos2 -o /proj/out/hello_app /proj/out/hello.o Compilation passes perfectly, but linking stucks with following: Undefined symbols for architecture x86_64: "start",

What's the best way to handle incoming messages?

泪湿孤枕 提交于 2019-12-10 12:53:35
问题 I'm writing a server for an online game, that should be able to handle 1,000-2,000 clients in the end. The 3 ways I found to do this were basically: 1 thread/connection (blocking) Making a list of clients, and loop through them (non-blocking) Select (Basically a blocking statement for all clients at once with optional timeout?) In the past I've used 1, but as we all know, it doesn't scale well. 2 is okay, but I have mixed feelings, about one client technically being able to make everyone else

Fibers over Threads in D

99封情书 提交于 2019-12-10 12:47:01
问题 I'm experimenting with threads and Fibers in D and I was wondering if it is possible to run a Fiber on a different CPU as the main thread is running. And if this is not the case then what would be the reason of using Fibers over Threads. (Practical examples are very welcome) I tried to write some initial program with Fibers where I switch to the next fiber after some time. Howhever I noticed that the cpu usage stays only on one cpu. The documentation of D states: Please note that there is no

multithreading in D with for loop

馋奶兔 提交于 2019-12-10 04:24:57
问题 I know that Rust can run loops with lightweight threads. Something like: use task::spawn; fn main() { for 100.times { do spawn { io::println("Hello"); } } How I can do this in D? 回答1: Relevant API doc: std.parallelism Here are a few of ways of accomplishing your example: Parallel foreach, using a TaskPool's parallel: foreach (i, val; taskPool.parallel(new int[50])) { writeln("Hello:", i); } Regular foreach, adding tasks to a task pool using put: foreach (i; 0 .. 50) { auto t = task!writeln(

Why can I not implement default constructors for structs in D?

北城余情 提交于 2019-12-10 02:23:46
问题 Writing code like struct S { this() // compile-time error { } } gives me an error message saying default constructor for structs only allowed with @disable and no body. Why?? 回答1: This is one of cases much more tricky than one can initially expect. One of important and useful features D has over C++ is that every single type (including all user types) has some initial non-garbage value that can be evaluated at compile-time. It is used as T.init and has two important use cases: Template

MPI and D: Linker Options

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 01:59:20
问题 I'm trying to use MPI with the D programming language. D fully supports the C ABI and can link with and call any C code. I've done the obvious stuff and translated the MPI header to D. I then translated a test program from Wikipedia to D. I compiled it with the following command: dmd test.d -L-lmpistubs It works when I just run ./test , and prints: 0: We have 1 processors However, when I run with mpiexec -n 8 test , it prints nothing. My understanding is that MPI executables require a bunch

When to delete in D?

淺唱寂寞╮ 提交于 2019-12-10 01:36:30
问题 I'm learning D from 8 years in C++. My question is with regards to D garbage collection - when do I use delete, and when don't I need to? 回答1: You don't. Delete is not to be used with D version 2 and intended to be removed from the language. What the hold up is, I am not sure. Instead you use a function, destroy(object), which calls the destructor where you can free resources that are not GC memory. The destructor will be caused again during GC collection of the objects own memory. This is

Platform independent file locking?

风流意气都作罢 提交于 2019-12-09 12:11:41
问题 I'm running a very computationally intensive scientific job that spits out results every now and then. The job is basically to just simulate the same thing a whole bunch of times, so it's divided among several computers, which use different OSes. I'd like to direct the output from all these instances to the same file, since all the computers can see the same filesystem via NFS/Samba. Here are the constraints: Must allow safe concurrent appends. Must block if some other instance on another

Setting up a working D2.x toolchain (with gtkd) on Ubuntu 10.04

青春壹個敷衍的年華 提交于 2019-12-09 03:34:22
问题 I've been playing around with D for a few days and was getting quite excited about it until, that is, I tried to get gtkd working. I've now wasted the best part of 3 days trying to get a working setup and am beginning to get (read; long ago got) a bit demoralised. I was wondering if anyone can help before I give up. A lot of the information I can find online is outdated so I'm not sure if I'm even right in thinking this is even possible. The rest of this is just about what I've tried so far