d

D language: initializing dynamic multidimensional array best practices?

自作多情 提交于 2019-12-05 03:30:39
Just curious if this is the best practice for initializing a dynamic, multidimensional array in D . There is a section on arrays in their language reference, but I'm not quite sure if it goes over what I'm trying to accomplish. class Map { Tile[][] tiles; this(uint width, uint height) { tiles.length = height; foreach (ref tilerow; tiles) tilerow.length = width; } } Map map1 = new Map(5000, 3000); // values determined at runtime (or an equivalent alternative like a typical for (y=0;y<height;y++) loop). My concern with this is that it reallocates each row of the array separately rather than the

ncurses api with the D Programming Language

旧时模样 提交于 2019-12-05 02:18:42
I am trying to teach myself AI using neural networks. Long story short, I wanted to create a simple graphic that would display what is happening in my program using ncurses. The tutorial that I am using is found here . I was under the impression that D was compatible with C and I could theoretically call C functions relatively easily. I find that not to be the case. I am a relatively novice programmer, so even the simplistic explanations are a little above my head. I found this here . D is designed to fit comfortably with a C compiler for the target system. D makes up for not having its own VM

mpi.h: Using a type w/o defining it?

丶灬走出姿态 提交于 2019-12-05 01:57:20
问题 I'm trying to translate the important parts of OpenMPI's mpi.h to the D programming language so I can call it from D. (HTOD didn't work at all.) I can't wrap my head around the following bits of code: typedef struct ompi_communicator_t *MPI_Comm; OMPI_DECLSPEC extern struct ompi_communicator_t ompi_mpi_comm_world; OMPI_DECLSPEC extern struct ompi_communicator_t ompi_mpi_comm_self; OMPI_DECLSPEC extern struct ompi_communicator_t ompi_mpi_comm_null; The problem is that ompi_communicator_t is

How to convert strings to floats with perfect accuracy?

岁酱吖の 提交于 2019-12-05 01:47:36
I'm trying to write a function in the D programming language to replace the calls to C's strtold. (Rationale: To use strtold from D, you have to convert D strings to C strings, which is inefficient. Also, strtold can't be executed at compile time.) I've come up with an implementation that mostly works, but I seem to lose some precision in the least significant bits. The code to the interesting part of the algorithm is below and I can see where the precision loss comes from, but I don't know how to get rid of it. (I've left out a lot of the parts of code that weren't relevant to the core

When to delete in D?

痞子三分冷 提交于 2019-12-05 00:50:48
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? 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 explained in " The D Programming Language ". The idea is to reclaim resources earlier than what the GC would

Does D have 'newtype'?

*爱你&永不变心* 提交于 2019-12-04 20:33:34
问题 Does D have 'newtype' (as in Haskell). It's a naive question, as I'm just skimming D, but Google didn't turn up anything useful. In Haskell this is a way of making different types of the same thing distinct at compile time, but without incurring any runtime performance penalties. e.g. you could make newtypes (doubles) for metres, seconds and kilograms. This would error at compile time if your program added a quantity in metres to a quantity in seconds, but would be just as fast at runtime as

How to use a C library from D?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 16:00:01
问题 Today I heard about the D programming and that it is compatible to C code. Nevertheless I haven't found any information on whether it is possible to use C libraries like GTK or PortAudio from D? If it is possible, could you explain how to do this? 回答1: It is possible to call C libraries from D. What you need to do is to convert the C header files to D. For the most part this is pretty straightforward, and there is a hard-to-use command-line tool to help automate the process. It's never really

How to fix “unrecognized option '-plugin`” when using gdc to compile D program?

前提是你 提交于 2019-12-04 11:14:04
I download the GDC for Linux , and try to build a simple D Program. After executing " gdc hello.d -o hello ", it outputs: [root@localhost nan]# gdc hello.d -o hello /usr/bin/ld: unrecognized option '-plugin' /usr/bin/ld: use the --help option for usage information collect2: error: ld returned 1 exit status Then I use " gdc -v hello.d -o hello " command, and try to find the root cause. It displays: ...... COLLECT_GCC_OPTIONS='-v' '-o' 'hello' '-shared-libgcc' '-mtune=generic' '-march=x86-64' /home/nan/x86_64-gdcproject-linux-gnu/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/collect2 -plugin

nginx, fastcgi and open sockets

為{幸葍}努か 提交于 2019-12-04 08:27:42
问题 I'm experimenting using fastcgi on nginx, but I've run into some problems. Nginx doesn't reuse connections, it gives 0 in BeginRequest flags, so the application should close the connection after the request has finished. I have the following code for closing: socket.shutdown(SocketShutdown.BOTH); socket.close(); The problem is that the connections are not actually closed.. They linger on as TIME_WAIT, and nginx (or something) wont't keep opening new connections. My guess is I'm doing

D exit statement

核能气质少年 提交于 2019-12-04 08:20:39
Does D have an exit statement, similar to the one in java, python, c/c++. Which will (big shocker) exit execution of the program? Something like exit(); If you want exit , then use C's exit function. import core.stdc.stdlib; void main() { exit(-1); } I'm not quite sure how that affects the D runtime and whatnot though. It might be that stuff doesn't get cleaned up like you'd normally want, or it might be just fine. I wouldn't really advise using it in general though, since there are usually better ways to handle exiting a program. But the declaration for the C function is in druntime, so it's