|
i wonder somebody can help me to sort this program. all my hair already turn white
i'm trying to make dynamic array library which can expand, add, delete,..n sort of. actually this one is my programming class assignment. for some func i haven't got a clue how to do. here's details
template <typename t="">
class DArray
{
public:
DArray(); // create default obj which will have unitsize of 64
DArray(size_t); // create dynamic array
DArray(size_t, const T &); // darray which has logical size = input
DArray(const DArray &); // copy darray, right hand side
template <typename t2=""> // *don't know how to do this
DArray(const DArray<t2> &); //
~DArray(); // destructor
DArray& operator=(const DArray &); //?teacher said to throw bad_alloc. ??
template <typename t2=""> //*don't know this 1 either
DArray& operator=(const DArray<t2> &); //
T & operator[] (size_t); //throw (invalid index) this 1 also i dunno
const T & operator[] (size_t) const; // problem here 2
size_t size() const; // return the logical size of darray
void resize(size_t, const T & = T());//resize darray(logical)as user specify
void append(const T &); //add new data to darray
bool remove_last(); //remove last data from darray
void clear(); // not sure about this one
bool empty() const; // logical size empty or not
size_t capacity() const; //return the current buffer size
void reserve(size_t); //?get the buffer size as user want to. ??
private:
size_t arrSize;
size_t buffSize;
const unsigned unitSize;
unsigned char * myheap;
T * buffer;
};
template <typename t="">
DArray<t>::DArray() : arrSize(0), buffSize(0), buffer(NULL), myheap(NULL), unitSize(sizeof(T))
{
try { myheap = new unsigned char [unitSize * 32]
buffSize = 32;
buffer = reinterpret_cast<t*> (myheap); // dunno this one right or wrong
}
catch(std::bad_alloc &)
{
}
}
template <typename t="">
DArray<t>::DArray(size_t initSize) : arrSize(initSize), buffSize(initSize), buffer(NULL), myheap(NULL), unitSize(sizeof (T))
{
if( arrSize > 0 ){
if( arrSize < 32) buffSize = 32;
else buffSize = arrSize + 32;
myheap = new unsigned char [buffSize * unitSize];
buffer = new (myheap) T[arrSize];
}
}
template <typename t="">
DArray<t>::DArray(size_t initSize, const T & init_value) : arrSize(initSize), buffSize(initSize * 2), buffer(NULL), myheap(NULL), unitSize(sizeof(T))
{
if( arrSize > 0 ){
myheap = new unsigned char[buffsize * unitSize];
buffer = reinterpret_cast<t*> (myheap);
for (size_t i =0; i < arrSize; ++i)
new (buffer + i) T(init_value);
}
}
template <typename t="">
DArray<t>::DArray (const DArray & rhs) : arrSize(0), buffSize(0), buffer(NULL), myheap(NULL), unitSize(sizeof(T))
{
*this = rhs; // can i do something like this?
}
template <typename t2=""> // pls someone help don't know how to do this
DArray(const DArray<t2> &); //
template <typename t="">
DArray<t>::~DArray()
{
clear();
delete[] myheap;
}
template <typename t="">
DArray<t> & DArray<t>::operator= (const DArray<t> & rhs)
{
if( this == & rhs){
return * this;
}
else
{
clear();
arrSize = rhs.arrSize;
if( buffSize <= rhs.size()){
delete[] myheap;
buffSize = rhs.buffSize;
myheap = new unsigned char[buffSize * unitSize];
buffer = reinterpret_cast<t*> (myheap);
}
for( int i = 0; i < arrSize; i++){
new( buffer + i) T(rhs.buffer[i]);
}
}
return * this;
}
template <typename t2=""> //*don't know this 1 either
DArray& operator=(const DArray<t2> &);
template <typename t="">
T & operator[] (size_t); //
template <typename t="">
const T & operator[] (size_t) const;
template <typename t="">
size_t DArray<t>::size()const
{
return arrSize;
}
template <typename t=""> // hope this one correct
void DArray<t>::resize(size_t newSize, const T & = T())
{
if( newSize >= buffSize)
{
reverse ( newSize );
}
else arrSize = newSize;
}
template <typename t="">
void DArray<t>::append(const T & newItem) // need to used throw catch in this func ??
{
if( arrSize == buffSize){
size_t newCapacity = (buffSize + 1) * 2;
T * oldbuffer = buffer;
unsigned char * oldheap = myheap;
myheap = new unsigned char [buffSize * unitSize];
buffer = reinterpret_cast<t*> (myheap);
for( int i = 0; i < arrSize; ++i) {
new( buffer + i) T(oldbuffer[i]);
(&oldbuffer[i]) -> ~T(); // called destructor
}
delete[] oldheap;
buffSize = newCapacity;
}
reverse( newItem)
new (buffer + arrSize) T(newItem);
++arrsize;
}
template <typename t="">
void DArray<t>::clear()
{
for( size_t i = 0; i < arrSize; ++i)
( & buffer[i])-> ~T();
arrSize = 0;
}
template <typename t="">
bool DArray<t>::remove_last()
{
if ( empty()) return false;
--arrSize;
( & buffer[arrSize])->~T();
return true;
}
template <typename t="">
bool DArray<t>::empty() const throw()
{
if (arrSize == 0) return true;
else return false;
}
template <typename t="">
size_t DArray<t>::capacity() const
{
return buffSize;
}
template <typename t="">
void DArray<t>::reverse(size_t newSize)
{
//reverse to size which the user want
//help help
}
// pls correct me if i'm wrong
//thx in advance
|
|
|
|
|
This is the managed C++ board. You should post non-manage C++ questions on the
Visual C++/ MFC board[^].
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
hi everyone,
this is my problem:
I have a huge binary file.I have my application:"software",since which i want to import the binary file.
but the file is huge:4gig. so my application crashes when i try to import it.and i get an exception: outofmemory...
what can i do to split the file, and to load it piece by piece into memory.
PS:after i omport the file into memory i have to use its seismic data to do some 3D simuations.
someone has an idea?
thanks.
assia
hgfh
|
|
|
|
|
How are you importing the file? What functions/class(es) are you using?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
Hi Mark,
Thanks for you answer.
I lived the office. I will send you the pieces of code tomorrow.
Thanks.
assia
hgfh
|
|
|
|
|
Hello everyone,
As I said I have 4 giga of memory and the file is 5 giga.I use windows Vista64.
and VStudio2005.
Does the serialization work in this case?
What to do to load the file piece by piece?
Is it possible de developp my own serializer ? if yes, can you give me an idea please about how to do it?
Here is my function:
Sine my main class I call this import for differents files, and it is ok when they are not huge.
Here is my function:
FileFormat::openImport(CFile &file, const CString& filename, bool is_binary) const {
FileFormat *self = (FileFormat *) this;
self->filename_ = filename;
self->in_import_ = true;
self->current_line_ = 0;
CFileException file_exception;
if (is_binary) {
if (!file.Open(filename, CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite, &file_exception))
return openError(file_exception, filename, name_);
}
else {
if (!file.Open(filename, CFile::modeRead | CFile::typeText | CFile::shareDenyWrite, &file_exception))
return openError(file_exception, filename, name_);
}
return true;
}
Thanks.
assia
hgfh
|
|
|
|
|
You may want to look into using a File Mapping[^] so you can access the
entire huge file without loading the entire file into memory at once.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
This link may or may not apply to your situation but it is interesting:
http://www.dansdata.com/askdan00015.htm[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
hai
Can you please holp me reagarding where can i find the implementation of CRC12,CRC16 algorithms in pure c or c++.
KIRAN PINJARLA
|
|
|
|
|
kiran.pinjarla wrote: where can i find the implementation of CRC12,CRC16 algorithms in pure c or c++.
You mean somewhere other than the internet?
|
|
|
|
|
I am recording to current time, and compare with the old time which stored in a file. but here t4 is always one digit less.
for example, when I check file end.txt and start.txt, t4 is 22284, and t3 is 21975, no problem.
but when I calculate and output differ, it shows 2228-21975=-19747. t4 is wrong! what is the problem here?
<br />
int differ=0;<br />
int t3=0;<br />
int t4=0;<br />
time_t t1,t2;<br />
FILE * pFile; <br />
<br />
(void) time(&t2);
t4=(int)t2;<br />
pFile = fopen ("/root/pclinq/end.txt","r+");<br />
fprintf (pFile, "%d",t4);
fclose (pFile);<br />
<br />
<br />
pFile = fopen ("/root/pclinq/start.txt","r+");<br />
fscanf (pFile, "%d", &t3);
fclose (pFile);<br />
<br />
differ=t4-t3;<br />
<br />
<br />
printf("differ is %d-%d=%d\n",t4,t3,differ);
(solved)it turns out the last digit was a remaining one, for example,2228 is the real number recorded this time
-- modified at 8:51 Tuesday 17th July, 2007
|
|
|
|
|
bloodwinner wrote: (solved)it turns out the last digit was a remaining one, for example,2228 is the real number recorded this time
and I guess the more appropriate open mode for writing a file is "w+" ...
|
|
|
|
|
Dear Sir,
I am using Visual C++ NET 2005.
How can I know the character(if it's 1,A... etc) that I strike when I am in the textbox field in the Keydown event ?
|
|
|
|
|
KeyEventArgs.KeyCode and KeyEventArgs.KeyChar
|
|
|
|
|
Dear Sir,
I am using Visual C++ NET 2005.
|
|
|
|
|
mikobi wrote: I am using Visual C++ NET 2005.
Cool, do you have a question?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
How to specify out parameters in CLI/C++ like we do in C#?
|
|
|
|
|
I expect there is no specifically out parameters and in parameters in c++. But for out parameters we should use the reference variable or pointer variable. Like we need to use call by ref concept.
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
To create an out-only parameter, you need to use the Out Attribute and a tracking reference:
using namespace System;
using namespace System::Runtime::InteropServices;
public ref class Foo
{
public:
void Func([Out] String^% value)
{
value = "Hello";
}
};
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks George!
|
|
|
|
|
Oh. Really Thanks.
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
Is the static member variable in class will same for all objects of that class?
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
|
|
|
|
|
yes static member variables are same for all objects of the class. As the scope of static member variable is class level not of object level. Each object of the class can access and share static member of class.
Static member is accessed via class name and not by object name, like
//static member accessment
className.staticmember = someValue
//object level variable.
objName.objMember
-shoaib-
|
|
|
|
|
hello,
I have declared a classe, when i creat instance of this classe, it work but when I call a thread it does not work
Thread ^trd;
ThreadStart ^myThreadDelegate = gcnew ThreadStart(this, &BHIDS00::Form1::rep);
trd = gcnew Thread(myThreadDelegate);
trd->IsBackground = true;
trd->Start();
avec rep() { .....................} est une méthode que je veux appelé
or in this methode there are listView->items->add(".."); with thread it doesn't display in listview, and I do rep();
how i do work my methode using thread ???
Merci beaucoup
|
|
|
|
|