Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • b41dddd
  • /
  • test2.cpp
Raw File Download
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:f73794aad04fef33ecb20d94524affd2d159c9bb
directory badge Iframe embedding
swh:1:dir:b41dddd2eb7b13f8b7199d566241be68c78a83ab
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
test2.cpp
/*
 * The following program tests the ability of the garbage collector to detect
 * pointers to CmmObjects from the uncollected heap.
 */

#include <stdio.h>
#include <stdlib.h>
#include "cmm.h"

/* Cell type to build a list with. */

struct  cell : CmmObject  {
  cell *next;
  int  *value1;
  int  value2;

  cell()
    {
      next = 0;
      value1 = 0;
    }

  void traverse()
    {
      CmmHeap *heap = Cmm::heap;
      heap->scavenge((CmmObject **)&next);
      heap->scavenge((CmmObject **)&value1);
    }
};

typedef  cell* cellptr;

#define TOT	5000

struct  cella  {
  cellptr ptr[TOT];
};

Cmm dummy(CMM_MINHEAP, CMM_MAXHEAP, CMM_INCHEAP, CMM_GENERATIONAL,
	  CMM_INCPERCENT, CMM_GCTHRESHOLD, CMM_HEAPROOTS | CMM_STATS, 0);

main()
{
	cella*  pointers = new cella; // allocated in uncollected heap
	cellptr cl = NULL, cp;
	int i;

	/* Allocate TOT cells referenced from array pointers */
	for  (i = 0; i < TOT; i++)  {
	   cp = new cell;
	   pointers->ptr[i] = cp;
	   cp->value1 = 0;
	   cp->value2 = i;
	}

	/* Make a list of TOT cells, each pointing to itself */
	for  (i = 0; i < TOT; i++)  {
	   cp = new cell;	// garbage
	   cp = new cell;	// garbage
	   cp = new cell;	// garbage
	   cp = new cell;
	   cp->next = cl;
	   cp->value1 = &cp->value2;
	   cp->value2 = i;
	   cl = cp;
	}

	/* Verify that cells referenced from pointers still exist */
	for  (i = 0; i < TOT; i++)
	  if (pointers->ptr[i]->value2 != i) {
	    fprintf(stderr, "cell %d not valid\n", i);
	    abort();
	  }

	/* Verify that cell list is still correct */
	for  (i = 0; i < TOT; i++)  {
	  if  (cl->value2 != *cl->value1) {
	    fprintf(stderr, "cell list damaged\n");
	    abort();
	  }
	  cl = cl->next;
	}
	return 0;
}

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top