free


C/C++: A small tip for freeing dynamic memory

Taking into account the behavior of the free() function, it is a good practice to set your pointer to NULL right after you free it.

By doing so, you can rest assured that in case you accidentally call free() more than one times on the same variable (with no reallocation or reassignment in between), then no bad side-effects will happen (besides any logical issues that your code might be dealing with).

You can include free() from malloc.h and it will have the following signature extern void free(void *__ptr);.

Description of operation:

Free a block allocated by malloc, realloc or calloc.
The free() function frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc(), or realloc().  Otherwise, if free(ptr) has  already been called before, undefined behavior occurs.  If ptr is NULL, no operation is performed.

Working examples:


#include <stdio.h>
#include <malloc.h>

int main()
{
  printf("Hello, World!\n");

  void * c = malloc (sizeof(char) * 10);

  free(c);
  c = NULL;
  free(c);

  return 0;
}


#include <iostream>

int main()
{
  std::cout << "Hello, World!" << std::endl;

  void * c = malloc (sizeof(char) * 10);

  free(c);
  c = NULL;
  free(c);

  return 0;
}


Beta test dropbox and get even more free space!

We tried this and it works!

Dropbox is now offering a way of increasing your free space by trying out an Experimental build of the application that allows your machine to scan an external device, like a cell phone mounted as a hard disk, and automatically sync the contents of the folder with your dropbox account.

What they promised is that for every 500MB of uploaded material through the autorun feature on the device uploaded to your profile, you will get it back for free with a limit of going up to 5GB, which is not something to joke about especially for the folks that have 2GB or 2.25GB only. (Tip: you get the first 500MB by just uploading a single photograph :))

How to get and use this build:

  1.  Go to this site http://forums.dropbox.com/forum-build.php which will guide you to the page the build information
  2. Download one of the distributions, depending on your system. (The day this article was written this was the latest build for Windows:
    > Windows: http://dl-web.dropbox.com/u/17/Dropbox%201.3.14.exe
  3. Of course install it as usual, and when you are done make sure it is running
  4. After that, mount your mobile device as an external disk drive to your computer and wait for the autorun menu to appear (if it doesn’t go to ‘My Computer’, right click on the device and select autorun)
  5. From the new window select the dropbox functionality as follows and give it some time to do its magic 🙂

Note: All uploaded photos will be renamed to this format  “<Year>-<Month>-<Day> <Hour>.<Minute>.<Second?>-<Increasing Number if needed>”(e.g 2012-02-07 15.12.22.jpg) but they will not lose their EXIF information.

Note: You will be able to find your uploaded photographs in the folder ‘Camera Uploads’ in the main folder of your dropbox account.

Sources:
(2/1) – Experimental Forum Build – 1.3.12
(2/7) – Experimental Forum Build – 1.3.14
These threads could become obsolete any day now so be sure to check out this page (newer forum build), which we believe will keep on taking you to the latest information.