OTextStream::OTextStream(const char *sname, unsigned int stype, bool append) { if(sname == NULL) throw int(kParamErr); stream = New_OStream(sname, stype, append); if(stream == NULL) throw int(kCannotOpenFileErr); filename = new char[strlen(sname) + 1]; strcpy(filename, sname); }
void DefaultRenderFrontend::OpenStreams(bool append) { for(int i = 0; i < MAX_STREAMS; i++) { if(streams[i] != NULL) delete streams[i]; streams[i] = NULL; if(append) { OStream *os = NULL; if(streamnames[i] != NULL) { os = New_OStream(streamnames[i], POV_File_Text_Stream, true); if(os == NULL) POV_NAMESPACE::Warning(0, "Could not append stream to file %s.", streamnames[i]); } streams[i] = new DefaultStreamBuffer(os, (i == ALL_STREAM), (i == ALL_STREAM) || !consoleoutput); } else { OStream *os = NULL; if(streamnames[i] != NULL) { os = New_OStream(streamnames[i], POV_File_Text_Stream, false); if(os == NULL) POV_NAMESPACE::Warning(0, "Could not write stream to file %s.", streamnames[i]); } streams[i] = new DefaultStreamBuffer(os, (i == ALL_STREAM), (i == ALL_STREAM) || !consoleoutput); } } }
OStream *New_Checked_OStream(char *filename, unsigned int stype, bool append) { if(POV_ALLOW_FILE_WRITE(filename, stype) == true) return New_OStream(filename, stype, append); return NULL; }
/* Released all unfree'd memory from all pools */ void mem_release_all() { #if defined(MEM_RECLAIM) OStream *f = NULL; MEMNODE *p, *tmp; size_t totsize; Send_Progress("Reclaiming memory", PROGRESS_RECLAIMING_MEMORY); p = memlist; totsize = 0; #if defined(MEM_TRACE) if (p != NULL) f = New_OStream(MEM_LOG_FNAME, POV_File_Data_LOG, true); #endif while (p != NULL) { #if defined(MEM_TRACE) #if defined(MEM_TAG) if (!mem_check_tag(p)) Debug_Info("mem_release_all(): Memory pointer corrupt!\n"); #endif /* MEM_TAG */ totsize += (p->size - NODESIZE - (MEM_GUARD_SIZE * 2)); if (!leak_msg) { Debug_Info("Memory leakage detected, see file '%s' for list\n",MEM_LOG_FNAME); leak_msg = true; } if (f != NULL) f->printf("File:%13s Line:%4d Size:%lu\n", p->file, p->line, (unsigned long)(p->size - NODESIZE - (MEM_GUARD_SIZE * 2))); #endif #if defined(MEM_STATS) /* This is after we have printed stats, and this may slow us down a little, */ /* so we may want to simply re-initialize the mem-stats at the end of this loop. */ mem_stats_free(p->size); #endif tmp = p; p = p->next; remove_node(tmp); FREE(tmp); } if (f != NULL) delete f; if (totsize > 0) Debug_Info("\n%lu bytes reclaimed\n", totsize); poolno = 0; memlist = NULL; #endif #if defined(MEM_STATS) /* reinitialize the stats structure for next time through */ mem_stats_init(); #endif }
/* Releases all unfree'd memory from current memory pool */ void mem_release() { #if defined(MEM_RECLAIM) OStream *f = NULL; MEMNODE *p, *tmp; size_t totsize; p = memlist; totsize = 0; #if defined(MEM_TRACE) if (p != NULL && (p->poolno == poolno)) f = New_OStream(MEM_LOG_FNAME, POV_File_Data_LOG, true); #endif /* MEM_TRACE */ while (p != NULL && (p->poolno == poolno)) { #if defined(MEM_TRACE) #if defined(MEM_TAG) if (!mem_check_tag(p)) Debug_Info("mem_release(): Memory pointer corrupt!\n"); #endif /* MEM_TAG */ totsize += (p->size - NODESIZE - (MEM_GUARD_SIZE * 2)); if (!leak_msg) { Debug_Info("Memory leakage detected, see file '%s' for list\n",MEM_LOG_FNAME); leak_msg = true; } if (f != NULL) f->printf("File:%13s Line:%4d Size:%lu\n", p->file, p->line, (unsigned long)(p->size - NODESIZE - (MEM_GUARD_SIZE * 2))); #endif /* MEM_TRACE */ #if defined(MEM_STATS) mem_stats_free(p->size); #endif tmp = p; p = p->next; remove_node(tmp); FREE(tmp); } if (f != NULL) delete f; if (totsize > 0) Debug_Info("%lu bytes reclaimed (pool #%d)\n", totsize, poolno); if (poolno > 0) poolno--; #if defined(MEM_STATS) /* reinitialize the stats structure for next time through */ mem_stats_init(); #endif #endif /* MEM_RECLAIM */ }