std.file is more about files and directories, not file contents. I've abandoned std.stream.File some time ago. I just use std.stdio.File partly because stdio, stdout, and stderr are of that type anyway. It works with ranges as well.

should be re-named std.folder, then, or std.filesystem. having another "file" there is quite confusing. Oh, no! there is also a... std.cstream!


std.stdio.File provides name() for the name and getFP() if you want to access the underlying FILE*.

I understand that std.stdio.File is the newer approach. OK, I will try to use that instead. BUT: what is the equivalent of std.stream.File.writeBlock(const void* buffer, size_t size)? I see there is a std.stdio.rawWrite(T)(in T[] buffer);

But, my data is: a (byte*) pointer and a length. How do I write something like std.stream.File.writeblock(cast(byte*)p,cast(int)len) using std.stdio.File.rawWrite?

And why std.stream.File is not marked as deprecated if a better (newer) alternative exists?



> private void msf_init(MSFilter* f){ //a constructor
> printf("msf_binfile_init-start\n============================\n");
> MSF_State* s=ms_new!(MSF_State)(1);
> s.filedesc = new std.stream.File;
[...]
> f.data=s;

We are assuming that f never goes away and that f.data is not assigned anything else, right? Otherwise the garbage collector will destroy that MSF_State and reclaim its memory at an indeterminate time. Is it possible that you use the MSF_State object longer than you should, after it's lifetime ended? If you did, the object would look usable for a while until the GC collects it.

Yes, that should be the case. f is the mother structure (a pointer towards a MSFilter structure) that should never disappear and f.data should not be assigned somewhere else. I have several other "filters" implemented using the same schema and they seem to work quite well, except that they do not use files or... classes (I still cannot grasp that fundamental thing when a class instance is a variable and when it is a pointer; when is T x; and when is T* x = new T(); or, when is T* x=(T*)calloc(1,sizeof(T));)

For the record, here is the "main.d" filter:

=========================main.d===========================
import std.stdio;
import core.thread;
import std.math;
import mediastreamer2_layer;
import msf_sourcer_sinusoid;
import msf_converter_double2int16_t;
import msf_sinker_binaryfile;
import msf_processor_split;
import msf_sinker_void;

int main(char[][] args)
{
    MSTicker* ticker;
    MSFilter* src_sinus;
    MSFilter* cnv_dbl2int16_t;
    MSFilter* snk_sndcrd;
    MSFilter* snk_binfile;
    MSFilter* prc_split1;
    MSFilter* prc_split2;
    MSFilter* snk_void;

    printf("-------START PROGRAM-------\n");
    ms_init();
    src_sinus=ms_filter_new_from_desc(&msf_sourcer_sinusoid_desc);
cnv_dbl2int16_t=ms_filter_new_from_desc(&msf_converter_double2int16_t_desc); snk_sndcrd=ms_snd_card_create_writer(ms_snd_card_manager_get_default_card(ms_snd_card_manager_get())); snk_binfile=ms_filter_new_from_desc(&msf_sinker_binaryfile_desc);
    prc_split1=ms_filter_new_from_desc(&msf_processor_split_desc);
    prc_split2=ms_filter_new_from_desc(&msf_processor_split_desc);
    snk_void=ms_filter_new_from_desc(&msf_sinker_void_desc);
    double f0=1000.0;
        ms_filter_call_method(src_sinus,MSF_SOURCER_SINUSOID_SET_FREQ,&f0);
        double fe=4000.0;
        ms_filter_call_method(src_sinus,MSF_SOURCER_SINUSOID_SET_RATE,&fe);
    int fe_int=cast(int)round(fe);
        ms_filter_call_method(snk_sndcrd,MS_FILTER_SET_SAMPLE_RATE,&fe_int);
        string numefisier="file_givenname.bin";
        
ms_filter_call_method(snk_binfile,MSF_SINKER_BINARYFILE_OPEN,cast(void*)&numefisier);
    ms_filter_link(src_sinus,0,prc_split1,0);
    ms_filter_link(prc_split1,0,cnv_dbl2int16_t,0);
    ms_filter_link(prc_split1,1,snk_binfile,0);
    ms_filter_link(cnv_dbl2int16_t,0,snk_sndcrd,0);
    ticker=ms_ticker_new();
        ms_ticker_attach(ticker,src_sinus); //START
        Thread.sleep(dur!("seconds")(3));
        ms_ticker_detach(ticker,src_sinus); //STOP
        ms_ticker_destroy(ticker);
        ms_filter_call_method_noarg(snk_binfile,MSF_SINKER_BINARYFILE_CLOSE);
    ms_exit();
    printf("-------STOP  PROGRAM-------\n");
    return 0;
}
==============================================================

Finally: thank you very much for your help! I expected D to be a sort of "better C with *facultative* classes" but I find it to be quite... C#. Is my vision correct?

Reply via email to