473,473 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

dynamiczna alokacja pamieci

Witam,
na poczatek moze przedstawie moja sytuacje. Mam dynamiczna liste
odpowiedzialna za przechowywanie nazw plikow w danym katalogu. Jezeli
przechodze do innego katalogu musze ta liste wyczyscic i na nowo
przypisac wartosci dla jej elementow. Napisalem do tego osobna funkcje
i niestety problem jest taki ze przekazuje do niej referencje wskaznika
pokazujacego na ta moja liste, czasem zdarza sie ze po wyjsciu z
funkcji lista jest pusta pomimo tego ze nawet jak wskaznik jeszcze stoi
przy return'ie to wszystko jest ok (cala lista jest ladnie wypelniona).
A teraz fragment kodu:

List2* fill_list2(List *list_ptr, List2 * &list2_ptr, string path)
{

ifstream new_;
new_.open("d:\\dir.txt");
int pos = 36,i=1,count =0;
bool dir;
string temp;
unsigned int position;
position = list_ptr->read_element_form_list(path);

if(position)
{
//************************************************** *****************************
list2_ptr->deletethis();
//tutaj usuwam biezaca liste
list2_ptr = new List2;
//i od razu tworze nowa
//************************************************** *****************************

//malo wazne rzeczy
getline(new_.seekg(position), temp, '\n');
temp = temp.substr(14,string::npos);
getline(new_, temp, '\n'); //wczytuje enter
getline(new_, temp, '\n'); //wczytuje nowa linie
while(temp.length())
{
if(temp.find("File(s)")== -1 ) //zeby nie wczytywal . jako folderu

if (temp.length()!=37)
{
if(temp.find("<DIR>")!= -1)
{
dir = 1;
temp = temp.substr(pos, string::npos);

list2_ptr->add_to_list2(temp, dir, size) ;
count ++;
}
}
// sort(list2_ptr);
getline(new_, temp, '\n');
}

//********************* a tutaj zwracam adres tego
wskaznika
return list2_ptr;
}

}

jeszcze funkcja deletethis()

void deletethis()
{
if (next!=NULL)
{
next->deletethis();
}

delete this;
}

Wiec tak: usuwam cala listei tworze nowa zmieniajac adres wskaznika.
Czy to tutaj jest blad? Czy jezeli usuwam liste to wskaznik rowniez
jest usuwany? Dziwna sprawa jest to ze po wyjsciu z funkcji adres sie
zgadza jednak lista jest pusta. Przeciez jest ona tworzona operatorem
new wiec nie powinna miec zakresu lokalnego ? Ja juz nic nie rozumiem.
Aha - program jest w stanie przejsc kilka petli z ta funkcja i wywala
sie podczas wypelniania listy nazwami plikow z roznych folderow. Czasem
wywali sie to przy drugim wypelnieniu listy czasem przy 10.
Przepraszam jezeli opis mojego problemu jest niejasny, jednak siedze
nad tym juz od dobrych paru godzin i z minuty na minute glupieje coraz
bardziej, Prosilbym o jakies wskazowki teoretyczne gdzie moze byc blad.

A i jeszcze jedna rzecz ktora jest zapewne wazna : pracuje w VS 2005;

Dziekuje za wszelka pomoc
Pozdrawiam
Piotrek

Dec 22 '06 #1
1 3883
Sorry i've made an error during sending my post to discussion group. It
should be send to polish one;)
Marry christmas guys :)

btw i've already solved this problem.

Peter ;)

Dec 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sun6 | last post by:
this is a program counting words from "text_in.txt" file and writing them in "text_out.txt". it uses binary tree search, but there is an error when i use insert () thanks for any help ...
8
by: Michal J | last post by:
I don't know what I'm doing wrong ?? #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <string.h>
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.