What exactly is the function of dhea?

Prohormone. Dhea is one of the adrenal hormones. It is most noted for help with short term memory. It also helps with the production of Estradiol (estrogen) and testosterone. And it is noted to help with boosting the immune system.
PRE-ANDROGEN. Dhea is made in the adrenal gland & brain as a precursor steroid (building block) to androgens & estrogens. There is no evidence it aides memory. See fuller, sj; tan, rs, martins, rn (2007 sep). "androgens in the etiology of alzheimer's disease in aging men and possible therapeutic interventions.". Journal of alzheimer's disease : jad 12 (2): 129–42. Pmid 17917157.
Adrenal hormone. It converts to other hormones, like estrogen and testosterone. Multiple studies show that older people with higher levels exhibit better health then those with low levels. It can increase acne. It has been shown to have good effects on those with pain and is being investigated for use in lupus patients. It can raise testosterone in women but not much in men.