std.stream.File help required (and classes)

Ali Çehreli acehreli at yahoo.com
Tue Mar 27 13:41:45 PDT 2012


On 03/27/2012 04:58 AM, akaz wrote:

 > 2. is the std.stream.File the correct choice here? Should I use std.file
 > instead? Then, why so many file classes (count std.stdio.File too).

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.

 > 3. std.stream.File does not have, apparently, some easy-to-interogate
 > properties to know the name (path) and the state of the associated file.

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


 > 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.

Ali



More information about the Digitalmars-d-learn mailing list