Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C
Hi!!
I want to modular & parametrise coding in which all variables,file pointers,device handles are initialise in one function & release in another function,I don't get idea about it!!How does that?Please suggest me solution for better performance of code & solution.
Thanks in Advance!
Posted 21-Jan-13 2:52am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In C++ you may use RAII[^]. Do initialization in the constructor, do some cleanup in the destructor. Take special care of exceptions in the destructor.
 
In C you must tell the client of your code to follow the protocol: call first some invented Init(...) function, then at the end some invented Release(...) function. Both functions are part of your library and do what you require in your question.
Cheers
Andi
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 21-Jan-13 11:22am
   
RAII is a very beneficial thing, my 5. The question is too vague though...
—SA
Andreas Gieriet at 21-Jan-13 11:35am
   
Thank you for your 5!
I agree that this question is rather fuzzy. I read that the OP is in need of RAII. No clue, though, what it has to do with C...
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 271
1 OriginalGriff 253
2 nv3 50
3 VJ Reddy 45
4 Mehdi Gholam 45
0 Sergey Alexandrovich Kryukov 6,696
1 OriginalGriff 6,149
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100