Re: How can I allocate a int[] array on stack?

2021-03-25 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Mar 26, 2021 at 7:36 AM Daniel Kozak  wrote:

> On Fri, Mar 26, 2021 at 7:31 AM Daniel Kozak  wrote:
>
>> On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn <
>> digitalmars-d-learn@puremagic.com> wrote:
>>
>>> What's the equivalent of C's VLA in D? scoped from std.typecons
>>> doesn't seem to work with arrays. Should I use alloca() for my
>>> array or is there something else?
>>>
>>
>> https://dlang.org/library/std/array/static_array.html
>>
> Sorry I was misread this
>

You can use allocator:

import std.experimental.allocator.showcase;
import std.experimental.allocator;
import std.stdio;

StackFront!4096 stackAlloc;

void main() {
int[] a = stackAlloc.makeArray!int(2);
writeln(a);
}


Re: How can I allocate a int[] array on stack?

2021-03-25 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> What's the equivalent of C's VLA in D? scoped from std.typecons
> doesn't seem to work with arrays. Should I use alloca() for my
> array or is there something else?
>

https://dlang.org/library/std/array/static_array.html


How can I allocate a int[] array on stack?

2021-03-25 Thread Jack via Digitalmars-d-learn
What's the equivalent of C's VLA in D? scoped from std.typecons 
doesn't seem to work with arrays. Should I use alloca() for my 
array or is there something else?


Re: Contributing CDF bindings to Deimos

2021-03-25 Thread Chris Piker via Digitalmars-d-learn

On Friday, 26 March 2021 at 00:50:36 UTC, Jordan Wilson wrote:
Nice one. I've used HDF5/NetCDF, will have to check out and see 
what CDF offers.


AFAIK CDF is much simpler than NetCDF.  If you do generate CDF 
files and want other common tools to understand your data 
structures, use the ISTP metadata scheme:


  https://spdf.gsfc.nasa.gov/istp_guide/istp_guide.html

Since deimos.cdf just provides C bindings and type safety, a 
higher level module would be nicer.  Currently, the most natural 
interface to CDF files that I've used is the spacepy.pycdf python 
package.








Re: Contributing CDF bindings to Deimos

2021-03-25 Thread Jordan Wilson via Digitalmars-d-learn

On Thursday, 25 March 2021 at 04:00:33 UTC, Chris Piker wrote:

On Tuesday, 23 March 2021 at 05:54:13 UTC, mw wrote:

[...]


Okay, that's done.

The repo https://github.com/das-developers/deimos.cdf and 
package https://code.dlang.org/packages/cdf have been drafted 
and tested on Linux, I'm about to test on Windows and MacOS.  
As an aside, software developers at NASA Goddard have now heard 
of D which is nice.  They were pleased to see that it was 
supported by gcc. (Hat tip to the GDC team)


I've attempted to follow all guidelines as best I understood 
them, but this is my first package.  It likely has some style 
and functionality issues.  Is there a peer review stage to this 
process that is triggered automatically or could be requested?


Nice one. I've used HDF5/NetCDF, will have to check out and see 
what CDF offers.


Jordan


Re: How to delete dynamic array ?

2021-03-25 Thread mw via Digitalmars-d-learn

On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote:
On Tue, Mar 16, 2021 at 11:28:00PM +, mw via 
Digitalmars-d-learn wrote: [...]

suppose:

  double[] data;  // D type: dynamic array

As of 2021 what's the correct way to allocate and deallocate 
(free memory to the system immediately) D's dynamic array?

[...]

Note that T[] is just a slice, not the dynamic array itself. 
The dynamic array is allocated and managed by the GC when you 
append stuff to it, or when you create a new array with `new` 
or an array literal.


None of the latter, however, precludes you from using T[] for 
memory that you manage yourself. For example, you could do this:


double[] data;
data = cast(double[]) malloc(n * double.sizeof)[0 .. n];


correction: this should be:

n *= double.sizeof;
data = cast(double[])(malloc(n)[0 .. n]);  // i.e. slice 
n == malloc n



Now you have a slice to memory you allocated yourself, and you 
have to manage its lifetime manually.  When you're done with it:


free(data.ptr);
data = []; // null out dangling pointer, just in case

The GC does not get involved unless you actually allocate from 
it. As long as .ptr does not point to GC-managed memory, the GC 
will not care about it. (Be aware, though, that the ~ and ~= 
operators may allocate from the GC, so you will have to refrain 
from using them. @nogc may help in this regard.)



T





Re: Contributing CDF bindings to Deimos

2021-03-25 Thread Chris Piker via Digitalmars-d-learn

On Thursday, 25 March 2021 at 16:57:05 UTC, Bastiaan Veelo wrote:

On Thursday, 25 March 2021 at 04:00:33 UTC, Chris Piker wrote:
As an aside, software developers at NASA Goddard have now 
heard of D which is nice.  They were pleased to see that it 
was supported by gcc. (Hat tip to the GDC team)


That’s cool. I’d love to see NASA on 
https://dlang.org/orgs-using-d.html one day.


— Bastiaan.


I'd like that too, we'll see.

The next set of NASA C code that needs bindings is the navigation 
library at https://naif.jpl.nasa.gov/naif/index.html.  This is an 
older library and so it isn't listed in the expected location 
https://software.nasa.gov/


A next step for the the CDF bindings would be to parse the 
existing external text documentation for each function and output 
ddoc comments.  Text processing is not my forte so any hints or 
volunteers are more than welcome.  I'll open an issue for that on 
github.




Re: What happened to std.net.curl HTTP execute?

2021-03-25 Thread tastyminerals via Digitalmars-d-learn

On Wednesday, 17 March 2021 at 16:02:58 UTC, tastyminerals wrote:
I am using std.net.curl and the following chunk of code in many 
places:


"""
http.setPostData(userData, "application/json");
http.addRequestHeader("Accept", "application/json");
http.addRequestHeader("Authorization", "BEARER " ~ 
clientAccessToken);

auto jsonData = http.execute.parseJSON;
if (jsonData.isNull) {
"""

Today I tried to compile one of the scripts and it failed with

 Error: no property execute for type std.net.curl.HTTP

When was it removed? I checked GitHub history briefly but the 
latest change dates back to April 2020 when these scripts were 
not even written. How did they work couple of months ago? I am 
confused.


Ohh, I created a custom function "execute" which calls 
"HTTP.perform" :facepalm:

I need to take a rest.


Re: Contributing CDF bindings to Deimos

2021-03-25 Thread Bastiaan Veelo via Digitalmars-d-learn

On Thursday, 25 March 2021 at 04:00:33 UTC, Chris Piker wrote:
As an aside, software developers at NASA Goddard have now heard 
of D which is nice.  They were pleased to see that it was 
supported by gcc. (Hat tip to the GDC team)


That’s cool. I’d love to see NASA on 
https://dlang.org/orgs-using-d.html one day.


— Bastiaan.


Re: Contributing CDF bindings to Deimos

2021-03-25 Thread mw via Digitalmars-d-learn

On Thursday, 25 March 2021 at 04:00:33 UTC, Chris Piker wrote:
The repo https://github.com/das-developers/deimos.cdf and 
package https://code.dlang.org/packages/cdf have been drafted 
and tested on Linux, I'm about to test on Windows and MacOS.  
As an aside, software developers at NASA Goddard have now heard 
of D which is nice.  They were pleased to see that it was 
supported by gcc. (Hat tip to the GDC team)




Thanks for the contribution.

I've attempted to follow all guidelines as best I understood 
them, but this is my first package.  It likely has some style 
and functionality issues.  Is there a peer review stage to this 
process that is triggered automatically or could be requested?


No, D packages is mostly community driven, there is no formal 
process.


The more users use one package, the more feedback one will get, 
typically logged as  github issues, and people communicate on 
github.


You can check some of the most popular packages here:

https://code.dlang.org/?sort=score